为何无参数的Guid构造函数产生一个空的GUID,而不是默认生成的一个作为与Guid.NewGuid()?
是否有一个空的Guid?
特殊用途 解决方案为何无参数的Guid构造函数产生一个空的GUID,而不是默认生成的一个作为与Guid.NewGuid()?
简短的回答:因为语言/运行时没有让Guid类型的设计者定义默认的构造函数
这不仅是传统的价值是默认构造的结构是零,你根本无法定义默认构造函数的结构。当你说新的GUID()运行时给你,所有的字段都被初始化为它们的默认值的新对象:http://msdn.microsoft.com/en-us/library/ah19swz4%28VS.71%29.aspx
有些理由可以在这里找到:http://www.yoda.arachsys.com/csharp/faq/#struct.constructors
Why does the parameterless Guid constructor generate an empty GUID rather than default to a generated one as with Guid.NewGuid()?
Is there a particular use for an empty Guid?
解决方案Why does the parameterless Guid constructor generate an empty GUID rather than default to a generated one as with Guid.NewGuid()?
Short answer: Because the language/runtime didn't let the designer of the Guid type define a default constructor.
It's not only conventional that the value of a "default-constructed" struct is zero, you simply cannot define a default constructor for a struct. When you say new Guid() the runtime gives you a new object where all the fields are initialized to their default values: http://msdn.microsoft.com/en-us/library/ah19swz4%28VS.71%29.aspx
Some rationale can be found here: http://www.yoda.arachsys.com/csharp/faq/#struct.constructors