struct
struct 主要特性如下
一、一個 struct 包含了欄位與建構式如下
public struct Coords
{
    public int x, y;
    public Coords(int p1, int p2)
    {
        x = p1;
        y = p2;
    }
}
二、struct 不接受無參數建構子,也不接受 struct 裡的欄位直接給初始值

三、可以用 new 來宣告一個 struct,其欄位將會給預設值
using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Coords b = new Coords();
            Console.WriteLine(b.x + " " + b.y);
        }
    }
    public struct Coords
    {
        public int x, y;
        public Coords(int p1, int p2)
        {
            x = p1;
            y = p2;
        }
    }
}
其結果為
![]()
四、如果直接宣告一個 struct,則需要對其欄位給值才能使用
using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Coords b;
            b.x = 0;
            b.y = 0;
            Console.WriteLine(b.x + " " + b.y);
        }
    }
    public struct Coords
    {
        public int x, y;
        public Coords(int p1, int p2)
        {
            x = p1;
            y = p2;
        }
    }
}
五、struct 不能被另一個 struct 繼承,這也是跟 class 的最大差別
參考資料: