Wednesday, January 20, 2010

Private setter for public getter

Hello Friends,

Now i am showing you some very good features of Net 2.0 over .Net 1.0.
Suppose you want to expose a public property. So for that you have
public getter method but what about its setter method.
from .net 2.0 tou can have a private setter for a public getter too like this.

private int x;
public int X
{
get { return x; }
private set { x = value; }
}

1 comment:

  1. Is there a way to serialize that class with a property defined like that?

    ReplyDelete