The types of properties in C# will be covered in this blog.
In C#, there are three different types of properties.
- Properties that don’t have a set accessor are known as read-only properties.
-
private readonly int rollNo = 1; public int RollNo { get { return rollNo; } }
-
- Properties that are deemed write-only are those lacking a get accessor.
-
private int rollNo; public int RollNo { set { rollNo = value; } }
-
- Properties that have a get and set accessor are referred to as read-write properties since they have both of these features.
-
private int rollNo; public int RollNo { get { return rollNo; } set { rollNo = value; } }
-
In summary, C# properties calculate data before enabling it to be edited. When data is amended, properties have the option of performing an action like raising an event or altering the value of other fields.