Introduction:

In this blog we can see what is the difference between field & property in C#.

What is Field in C#?

Every object has traits and tendencies. The fields explain the features, and the methods describe the behavior’s. Fields like employee no., name, and department can be found in an employee object.

What is Property in C#?

There are no storage facilities on the premises. Accessors for the properties have executable statements that can be used to read and set values. A get accessor and a set accessor may be included in the accessor declarations. Assume that the Employee class has private fields like employee no., name, and department. These fields are not immediately accessible from outside the class. As a result, the programmer can set and retrieve values using properties. Consequently, it is possible to access the private fields via the properties.

Difference between field and property :

Field : Any variable that is explicitly stated in a class is referred to as a field.

A field can be used to describe an object’s or class’s features.

Property:

A property is a member that provides a flexible mechanism to read, write or compute the value of a private field.

A field’s values may be received by or set using a property.

 

For any Help or Queries Contact us on info@crmonce.com or +918096556344