C# Structs

A C# struct is a lightweight alternative to a class that can contain data members and functions. It can do almost everything a class can do but is smaller memory-wise than a class. A C# structs is a value type, and classes are a reference type. When would you use a struct? When you want to represent simple data structures, and you’re not going to instantiate a bunch of them. A struct does not support user-specified inheritance and all struct types inherit from the System.ValueType which inherits from System.Object.

    struct Airplane
    {
        public int Speed { get; set; }
        public int Altitude { get; set; }

        public string AirplaneStats()
        {
            return "The airplane is going " + Speed + " Knots and an altitude of " + Altitude;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Airplane myAirplane = new Airplane();

            myAirplane.Altitude = 35000;
            myAirplane.Speed = 350;

            Console.WriteLine(myAirplane.AirplaneStats());

            Console.Read();

        }
    }