Different Property Types In C#

The types of properties in C# will be covered in this blog.

In C#, there are three different types of properties.

  1. 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;
          }
      }
  2. Properties that are deemed write-only are those lacking a get accessor.
    • private int rollNo;
      public int RollNo {
          set {
              rollNo = value;
          }
      }
  3. 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.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories