属性:Get Accessor 与 Expression-Bodied 成员
Properties: Get Accessor vs Expression-Bodied Member
这些似乎实际上是等价的:
bool PropertyAsExpressionBody => true;
bool PropertyAsGetAccessor {
get {
return true; // or just { get => true; }
}
}
声明一个 get
访问器(假设你没有 want/need 一个 setter)和一个表达式体 属性 之间有什么功能上的区别吗?
他们是同一张照片..东西.
见here:
Starting with C# 6, read-only properties can implement the get
accessor as an expression-bodied member. In this case, neither the get
accessor keyword nor the return keyword is used.
和here:
Starting with C# 7.0, you can use expression body definitions to
implement property get and set accessors.
这些似乎实际上是等价的:
bool PropertyAsExpressionBody => true;
bool PropertyAsGetAccessor {
get {
return true; // or just { get => true; }
}
}
声明一个 get
访问器(假设你没有 want/need 一个 setter)和一个表达式体 属性 之间有什么功能上的区别吗?
他们是同一张照片..东西.
见here:
Starting with C# 6, read-only properties can implement the get accessor as an expression-bodied member. In this case, neither the get accessor keyword nor the return keyword is used.
和here:
Starting with C# 7.0, you can use expression body definitions to implement property get and set accessors.