Select Page

Previously to add a property to a class would involve creating a private variable to store the value as well as the get and set property accessors to expose it.

private string headingFontName;
public string headingFontName
{
get{return headingFontName;}
set{headingFontName = value;}
}

Auto-implemented properties allow you to replace the above with:


public string headingFontName { get; set; }

And if you want a read or write only property make one of the accessors pivate. So a read only property would be:


public string headingFontName { get; private set; }

You can access the value from within the class by using the property.


headingFontName = “Arial”;

%d bloggers like this: