What is the => assignment in C# in a property signature

前端 未结 7 1107
执念已碎
执念已碎 2020-11-22 00:29

I came across some code that said

public int MaxHealth => 
         Memory[Address].IsValid ? 
         Memory[Address].Read(Offs.Life.MaxHp)          


        
7条回答
  •  礼貌的吻别
    2020-11-22 01:17

    You can even write this:

        private string foo = "foo";
    
        private string bar
        {
            get => $"{foo}bar";
            set
            {
                foo = value;
            }
        }
    

提交回复
热议问题