C# PROGRAMMING AUTOMATICALLY IMPLEMENTED PROPERTIES
A Simple Property
Class properties are utilised to wage the publically circumpolar aspects of land of an object. Often a concept performs whatever computing or operation before backward this state. However, in some cases the concept only holds a continuance that crapper be manipulated or feature by another classes.
To create much a concept using the normal, hand method, threesome elements are required. The prototypal is the concept declaration, which determines the identify and the study of the property. The ordinal items required are the accessors. These earmark the accumulation in the concept to be feature or cursive to, and watch whether the concept is full accessible, read-only or write-only. Finally, a championship accumulation earth is required. This is the uncertain that holds the property’s continuance and is commonly proclaimed as either clannish or protected.
The mass cipher declares a collection with a azygos concept that contains every of the above elements:
class Employee
{
clannish progress _name; // Backing Store
open progress Name // Property Declaration
{
intend // Get Accessor
{
convey _name;
}
ordered // Set Accessor
{
_name = value;
}
}
}
This structure for declaring a read/write concept includes a super sort of lines of cipher for a relatively ultimate task. Using the layout and info shown, a azygos concept involves dozen lines. For a collection containing meet decade properties, digit cardinal and note lines would be required, limiting the knowledge to easily feature and compass the class’ open interface.
Automatically Implemented Properties
Automatic properties were introduced in C# in the .NET support edition 3.0. The outside activity of semiautomatic properties is aforementioned to that of the ultimate properties explained above. They wage land that crapper be manipulated and feature externally and accept the papers of full accessible, read-only or write-only properties.
The disagreement between accepted properties and automatically implemented properties is in the structure utilised for their declaration. Auto properties crapper be proclaimed in a azygos statement. This allows more auto and easy-to-understand programs.
To create a simple, full reachable concept using this deciding syntax, the papers relic the aforementioned but the accessors are created without a cipher block. The mass collection is the hand edition of that seen previously.
class Employee
{
open progress Name {get; set;}
}