In C#. properties are the extension of data fields. In the object-oriented programming language, encapsulation and hiding are the pillars. By using various access modifiers like private, public, protected, internal etc, we can control the accessibility of the class members.
Usually, inside a class, we declare a data field as private and provide a set of public SET and GET methods to access the data fields. Since this is not a good programming practice to give direct accessibility of data fields outside the class.
Let us suppose we have an employee class with three fields, Empid, name and company name.
If we give direct access to these three fields outside the class, there is a chance to get false data as below.
In any organization, the employee never has an ID with the negative number as well null value to the Employee name. So, while supplying the required data it is mandatory to identify whether the data is valid or not.
So, by applying data encapsulation and hiding techniques, we should stop direct access to the data fields and provide through properties as below
Using GET() and SET() methods we can read value and assign to the field members.
GET() represents read property and SET() represents write property.
A property with GET() only, it is a read-only property. We can't manipulate the value on it. In the above example, Company name is common for all employees across the organization. So, we should stop overwriting on it. So, it has GET() attribute only.




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery
Thanks for a great tips, This would be a different idea from the routine tips.
ReplyDeleteSelenium Training in chennai | Selenium Training in anna nagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery
Start by painting your home outsides, pruning and cleaning the nursery. Eliminate all the messiness from your nursery and even the land. Homes for sale in Huntington Hills
ReplyDelete