new Guid() and Guid.Empty produces the same results (all-0 guid (00000000-0000-0000-0000-000000000000).
var guid = new Guid();
Console.WriteLine(guid);//00000000-0000-0000-0000-000000000000
var emptyGuid = Guid.Empty;
Console.WriteLine(emptyGuid);//00000000-0000-0000-0000-000000000000
Is this a two different manners to do the same thing ? readabilty reasons ? or i'm missing something ?
Guid is a struct. All structs have an implicit default constructor which initializes all members to their default value. In Guid, you see that as setting all it's composite members to 0.
Guid.Empty simply caches the default value via the invocation of the default constructor:
public struct Guid : IFormattable, IComparable, IComparable<Guid>, IEquatable<Guid>
{
public static readonly Guid Empty = new Guid();
}
Guid is a struct. All structs have an implicit default constructor which initializes all members to their default value. In Guid, you see that as setting all it's composite members to 0.
Guid.Empty simply caches the default value via the invocation of the default constructor:
public struct Guid : IFormattable, IComparable, IComparable<Guid>, IEquatable<Guid>
{
public static readonly Guid Empty = new Guid();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With