困った時の自分用メモ

読んだ本を考察してメモったり、自分でいじった物の感想をメモったりする場。週1更新を目指します。

C#の話~メンバに付いてる「=>」って何?~

ufcpp.net
expression-bodied なプロパティ

という物らしい。

簡単に言えば、getプロパティを簡単に記述したもの。
getのみであれば、この記法が使える。

public class Test3 : MonoBehaviour
{
    private int XValue = 5;
    private int YValue = 3;

    public int Value { get { return XValue + YValue; } }
    public int Value2 => XValue - YValue;
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log(Value);   // 8
        Debug.Log(Value2);  // 2
    }
}