Use Properties to get and set private member variable : private « Class « C# / CSharp Tutorial






using System;

class Circle{
    int radius;
    
    public int Radius{
        get{
            return(radius);
        }
        set{
            radius = value;
        }
    }

}
class MainClass
{
    public static void Main()
    {
        Circle c = new Circle();
        c.Radius = 35;
    }
}








7.16.private
7.16.1.Define private constructors to make a singleton
7.16.2.Use Properties to get and set private member variable
7.16.3.private static and const Fields
7.16.4.Using Methods to change private fields