Home >Backend Development >C++ >What is the C# `=>` Operator in Properties and Methods?
`` `` `` `Operator in Properties and Methods?
" /> <code class=" language-csharp>public int MaxHealth =>
Memory[Address].IsValid ?
Memory[Address].Read<int>(Offs.Life.MaxHp) :
0; </p>
<p>
</p> The difference between the main attribute members and field initialization of the above expression is: <pre class="brush:php;toolbar:false"><code class="language-csharp">public int MaxHealth
{
get
{
return Memory[Address].IsValid ? Memory[Address].Read<int>(Offs.Life.MaxHp) : 0;
}
}</code>
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. =>
<code class="language-csharp">public int Add(int x, int y) => x + y;</code>
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.
<code class="language-csharp">public int Add(int x, int y) { return x + y; }</code>
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!