随着C#6的推出,一些新功能也应运而生,其中包括getter-only auto-properties和property-like function members。我想知道这两种属性之间有什么区别?是否有任何理由我更喜欢其中的一种?
public class Foo
{
public string Bar {get;} = "Bar";
public string Bar2 => "Bar2";
}
我知道{get;} =
只能通过静态调用或常量值设置,而=>
可以使用实例成员。但在我的特定情况下,我应该选择哪个并为什么?