How do I ignore set and get when assigning or retrieving a value?

Posted by cbsch on Stack Overflow See other posts from Stack Overflow or by cbsch
Published on 2010-03-21T02:49:11Z Indexed on 2010/03/21 2:51 UTC
Read the original article Hit count: 376

Filed under:
|

Hello. Is it possible to ignore set and get when I'm assigning to or retrieving a value?

In specific, I'm inheriting from a class that has a property declared like this:

public Int32 Value { get; set; }

What I'd like to do is to override it and do something useful in those set and get's. The problem appears when I override it, I also have to manually assign, or return the value from the property. If I do something like this:

override public Int32 Value
{
    get
    {
        return this.Value;
    }
    set
    {
        this.Value = value;
        // do something useful
    }

Then I'm creating an infinite loop. Is there a way to set or get the value without invoking the code in set and get, or do I have to make a separate name for the actual variable?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#