返回
Featured image of post C♯ - 自訂類型(Custom types) - 結構(Struct) 筆記

C♯ - 自訂類型(Custom types) - 結構(Struct) 筆記

結構(Struct) 筆記

官方基本範例

public struct Coords
{
    public Coords(double x, double y)
    {
        X = x;
        Y = y;
    }

    public double X { get; }
    public double Y { get; }

    public override string ToString() => $"({X}, {Y})";
}

Struct 基本限制

  • 使用函式時,需有相對應參數,上方範例舉例new Coords(1,2)
  • Struct內可宣告 staticconst或其他靜態屬性
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus