`` `` `` `Operator in Properties and Methods?
" />
public int MaxHealth => Memory[Address].IsValid ? Memory[Address].Read<int>(Offs.Life.MaxHp) : 0;
The difference between the main attribute members and field initialization of the above expression is:
public int MaxHealth { get { return Memory[Address].IsValid ? Memory[Address].Read<int>(Offs.Life.MaxHp) : 0; } }
Getter expressions are calculated every time access attributes.
Field initialization device expression is calculated only once when instantiated type.
This code is equivalent to the following methods:
Expressive main method is suitable for all member types except nested types, events and fields. =>
public int Add(int x, int y) => x + y;
The main member of the expression is a grammar candy characteristic, which is allowed to simplify attributes and methods by allowing Getter to represent a single expression. They provide simple grammar for only Getter attributes and simple methods.
public int Add(int x, int y) { return x + y; }
The above is the detailed content of What is the C# `=>` Operator in Properties and Methods?. For more information, please follow other related articles on the PHP Chinese website!