Accessing Structures with Properties and Public Members : Properties « struct « C# / CSharp Tutorial






public struct StructWithPublicMembers {
    public int X;
    public int Y;
}

public struct StructWithProperties {
    private int PrivateX;
    private int PrivateY;

    public int X {
        get {
            return PrivateX;
        }
        set {
            PrivateX = value;
        }
    }

    public int Y {
        get {
            return PrivateY;
        }
        set {
            PrivateY = value;
        }
    }
}


public class MainClass {
    public static void Main() {
        StructWithPublicMembers MembersStruct;
        StructWithProperties PropertiesStruct = new StructWithProperties() ;

        MembersStruct.X = 100;
        MembersStruct.Y = 200;

        PropertiesStruct.X = 100;
        PropertiesStruct.Y = 200;
    }
}








6.6.Properties
6.6.1.Use property in a struct
6.6.2.Accessing Structures with Properties and Public Members