Google News
logo
C# - Interview Questions
What are Properties in C#?
Properties are the special type of class members that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and helps to promote the flexibility and safety of methods. Encapsulation and hiding of information can also be achieved using properties. It uses pre-defined methods which are “get” and “set” methods which help to access and modify the properties.
 
Accessors : The block of “set” and “get” is known as “Accessors”. It is very essential to restrict the accessibility of the property. There are two types of accessors i.e. get accessors and set accessors. There are different types of properties based on the “get” and set accessors:
 
Read and Write Properties : When property contains both get and set methods.

Read-Only Properties : When property contains only the get method.

Write Only Properties : When property contains only set method.

Auto Implemented Properties : When there is no additional logic in the property accessors, and it introduces in C# 3.0.
Advertisement