Why does the parameterless Guid constructor generate an empty GUID?

This behavior is consistent with the rest of the value types in the .Net framework. When "newing up" a value type, a default value is used. This just happens to be the default for Guid similar to Int32's default value of 0.


An empty guid is useful to represent the lack of a Guid. Since value types are not nullable (by default yes you can use nullable).

For example I use a Guid as Id properties a lot cause they are real easy to work with. So one way to see if an object has been persisted (Which is when it gets its Id), I can check the value of id against 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: https://web.archive.org/web/20131102220804/http://www.yoda.arachsys.com/csharp/faq/#struct.constructors


I think it's conventional that the default value, of a struct or of a built-in type, is zero.