Hooked on LINQ

Hooked on LINQ - Developers' Wiki
for .NET Language Integrated Query

Quick Search

Advanced Search »
Back to C# Language Enhancements.

Automatic Properties are a shorthand syntax for declaring a property that reads and writes its value from a simple backing field.

public string Name { get; set; }

is the same as the following code:

private string _name;
 
public string Name
{
    get { return _name; }
    set { _name = value; }
}

The backing field is not publically accessible by design. The traditional property declaration is still the tool of choice when more complex logic in either the getter or setter is needed. Both automatic properties and traditional properties can be used in the same class and interchanged at any time.

Edit

References

Google search: Automatic Properties C#

If you would like to comment on this page, click on the Discuss button located on the top-right of each page. Feel free to edit any mistakes or omissions you find. If you have an objection or find in-appropriate content then contact the administrator. This website is not affiliated with Microsoft®, all content and opinions are those of the specific author and some advice, solutions and article may contain unintentional errors - please use care. Powered by ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.