Create A Struct Using Default Constructor : struct definition « struct « C# / CSharp Tutorial






using System;

    public struct Location
    {
        public int X { get; set; }
        public int Y { get; set; }

        public Location(int x, int y)
            : this()
        {
            X = x;
            Y = y;
        }

        public override string ToString()
        {
            return (String.Format("{0}, {1}", X, Y));
        }

    }

    public class Tester
    {
        static void Main()
        {
            Location loc1 = new Location();  // no call to the constructor
            loc1.X = 75;
            loc1.Y = 225;
            Console.WriteLine(loc1);
        }
    }








6.2.struct definition
6.2.1.Declare the Rectangle struct
6.2.2.Declaration of a struct and use it
6.2.3.Declare a struct
6.2.4.Use enum data type in a struct
6.2.5.Composite Struct
6.2.6.Create A Struct Using Default Constructor
6.2.7.Defining struct