c# – new GUID() returns 0

GUID stands for globally unique identifier.

GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens.

Here is an example {21EC2020-3AEA-4069-A2DD-08002B30309D}.

They may or may not be generated from random (or pseudo-random) numbers.

GUIDs generated from random numbers normally contain 6 fixed bits (these indicate that the GUID is random) and 122 random bits; the total number of unique such GUIDs is 222 (approximately 5.3×1036).

The probability of the same number being generated randomly twice is negligible;

Assuming uniform probability for simplicity, the probability of one duplicate would be about 50% if every person on earth as of 2014 owned 600 million GUIDs.





Do not use this way as it will only return with all zeros as shown below.

Guid  g1 = new Guid();       // g1 will return 00000000-0000-0000-0000-000000000000




Here is the correct way
Guid g1 = Guid.NewGuid();  //   g1 will return a proper GUID like {21EC2020-3AEA-4069-A2DD-08002B30309D}