Open In App

C# | Restrictions on Properties

Prerequisite: 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 help to promote the flexibility and safety of methods. Encapsulation and hiding of information can also be achieved using properties. It uses pre-define methods which are “get” and “set” methods which help to access and modify the properties.

Syntax:



<access_modifier> <return_type> <property_name>
{
        get { // body }
        set { // body }
}

Restrictions on Properties: We have to follow a few rules or restrictions while writing properties which are as follows:


Article Tags :
C#