Thursday, February 15, 2007

C# internal Setter

I just read a great blog about having different access modifiers for the get and set methods of a variable.

In order to have different levels you just add the access modifier to the set method.

public string Description {
get { return description; }
internal set { description = value; }
}


This is awesome. I've had many times when I wanted to restrict the setter to my local class, so there is a controlled validation before setting, but not allow any external class to set the value directly.

No comments: