Converting Variables into Property in C#

What are Properties: Properties are named members of classes, structures, and interfaces

It is basically used when we want to access the private members of the class by another class.
Generally if we make the members as public, then anyone can misuse it so to prevent using public keyword we can use Properties.

public class Test{
  	private string var1;
}

public class Test2:Test{
  public string var2;
  
  var2=var1; //this will give error since the variables in class Test in private
}
//Even if you use protected word in class Test you will receive the error as below:
// CA1051: Do not declare visible instance fields 
//Link: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1051


//to solve this we will use the concept of property
public class Test{
  	protected string var1 {get;private set;} //this will make this as a property where read is possible but not write
}

public class Test2:Test{
  public string var2;
  
  var2=var1; //this will give not give error
}

This is the most basic use of Property
For more in-depth : C# | Properties – GeeksforGeeks

Happy Coding 🙂