vendredi 24 juin 2016

Change Base class field value from Derived

I have a question if it is possible to change field value of the base class, from derived class. In my case, i have two classes base class with windows form RichTextBox, and I want use derived class to clear RichTextBox.

Base class:

    class Program : Form
{
    public System.Windows.Forms.RichTextBox rtfCode;

    public Program()
    {
        rtfCode.Text = "some text";
    }
    static void Main(string[] args)
    {
        Program a = new Program();
        Console.WriteLine(a.rtfCode.Text);
        DerivedClass f = new DerivedClass();
        Console.WriteLine(a.rtfCode.Text);

    }

}

My Derived class

    class DerivedClass:Program
{
    public DerivedClass()
    {
        base.rtfCode.Clear();
        Console.WriteLine(base.rtfCode.Text);
    }
}

when i execute program on console i see only old tex.





Aucun commentaire:

Enregistrer un commentaire