In this article, we are going to talk about the use of properties in C# with examples.
What are the Properties in C#
A Property in C# is an extension of a field that provides a public way for the classes to read, write, and expose the private fields while hiding the implementation details.
Properties in C# are actually a special kind of getter and setter methods wrapped around a private variable. A get property accessor is used to retrieve the value and the set accessor is used to assign the new value.
In this article, we will understand the var keyword in C#.
var keyword in C#
The var keyword was introduced in C# 3.0 to declare an implicitly typed of local variable to hold any type of data. In implicitly typed variables, the type of the variable declared is decided by the compiler at the compile-time based on the type of the value that the variable is initialized with. The variable declared as var is mandatory to initialize at the time of declaration.
The following are the implicitly and explicitly typed variables declaration in C#.