new 关键字是调用结构的默认构造函数还是调用其成员的默认构造函数?
Does the new keyword calls the default constructor of the struct or does it call the default constructors of its members?
我了解到 C# 中的结构没有默认构造函数。但是当我使用new
关键字创建一个struct时,struct的成员会被初始化,那么这是怎么发生的,new
关键字是否调用了struct成员的默认构造函数呢?
does the new keyword calls the default constructors for the members of the struct?
否 - 每个成员都将被初始化为其默认值:值类型为 0(或其等效值);对于引用类型为 null。如果该结构包含另一个结构,该结构也将使用默认值构造。
来自MSDN:
Struct members are automatically initialized to their default values.
我了解到 C# 中的结构没有默认构造函数。但是当我使用new
关键字创建一个struct时,struct的成员会被初始化,那么这是怎么发生的,new
关键字是否调用了struct成员的默认构造函数呢?
does the new keyword calls the default constructors for the members of the struct?
否 - 每个成员都将被初始化为其默认值:值类型为 0(或其等效值);对于引用类型为 null。如果该结构包含另一个结构,该结构也将使用默认值构造。
来自MSDN:
Struct members are automatically initialized to their default values.