explain properties with syntax in c#
Answers
Explanation:
Property in C# is a member of a class that provides a flexible mechanism for classes to expose private fields. Internally, C# properties are special methods called accessors. A C# property have two accessors, get property accessor and set property accessor. ... The value keyword represents the value of a property
Property in C# is a member of a
class that provides a flexible mechanism
for classes to expose private
fields.
Internally,
C# properties are special
methods called accessors.
A C# property have two accessors,
get property accessor
and set property accessor
The value keyword represents
the value of a property.
Properties in C# and .
NET have various access levels
that is defined by an access modifier.
Properties can be read-write, read-only,
or write-only. The read-write property
implements both, a get and a set accessor.
A write-only property implements a set accessor,
but no get accessor. A read-only property
implements a get accessor, but no set accessor.
In C#, properties are nothing but a natural
extension of data fields.
They are usually known as 'smart fields'
in C# community. We know that data encapsulation
and hiding are the two fundamental
characteristics of any object oriented programming
language. In C#, data encapsulation is possible through either classes or structures.
By using various access modifiers like private,
public, protected, internal etc it is possible to control the accessibility of the class members.
Usually, inside a class, we declare a data field as private and will provide a set of public SET and GET methods to access the data fields.
This is a good programming
practice since the data fields are not directly accessible outside the class.
We must use the set/get methods to access the data fields.
An example, which uses a set of set/get methods, is shown below.
make my answer as brainlist