Passing data to overridden base method in C#

Posted by UpTheCreek on Stack Overflow See other posts from Stack Overflow or by UpTheCreek
Published on 2010-06-11T10:40:52Z Indexed on 2010/06/11 10:42 UTC
Read the original article Hit count: 175

Filed under:

Bit of a dumb question, but I'm wondering what the accepted way of passing data from back to an overridden base method is in c#.

e.g. I guess I could do:

class A
{
    int x;
    public virtual void DoStuff() {
        Console.WriteLine(x);
    }
}

class B : A
{
    public override void DoStuff() {
        x = 1;
        base.DoStuff();
    }
}

But is there a better method that for example doesn't require the use of a member variable?

© Stack Overflow or respective owner

Related posts about c#