这条带有静态 class 的自动实现属性的行是什么意思?
What does this line with auto-implemented properties with a static class mean?
我正在按照测试 azure 函数的说明进行操作 here,我遇到了这行代码:
public static NullScope Instance { get; } = new NullScope();
我读过 this SO 答案,所以我了解自动实现的属性,但我不知道它如何与 static
关键字结合使用。
这只是创建一个只能访问不能设置的新Nullscope吗?或者这会在您每次 get
时创建一个新的 NullScope 吗?如果可能,您能否扩展代码行以便更好地理解?
Is this just creating a new Nullscope that you can only access and not set?
是的,完全正确。
Or does this create a new NullScope every time you get it?
不,那看起来更像这样:
public static NullScope Instance
{
get => new NullScope();
}
请注意,前者有一个标准的自动实现 getter 并使用一些相对较新的语法为自动实现的后备成员设置一个值,而后者使用自定义 getter只是一个 "expression bodied member",当被调用时,returns 一个对象。
我正在按照测试 azure 函数的说明进行操作 here,我遇到了这行代码:
public static NullScope Instance { get; } = new NullScope();
我读过 this SO 答案,所以我了解自动实现的属性,但我不知道它如何与 static
关键字结合使用。
这只是创建一个只能访问不能设置的新Nullscope吗?或者这会在您每次 get
时创建一个新的 NullScope 吗?如果可能,您能否扩展代码行以便更好地理解?
Is this just creating a new Nullscope that you can only access and not set?
是的,完全正确。
Or does this create a new NullScope every time you get it?
不,那看起来更像这样:
public static NullScope Instance
{
get => new NullScope();
}
请注意,前者有一个标准的自动实现 getter 并使用一些相对较新的语法为自动实现的后备成员设置一个值,而后者使用自定义 getter只是一个 "expression bodied member",当被调用时,returns 一个对象。