Guid.NewGuid Method
.NET Framework 4
Updated: August 2011
Initializes a new instance of the Guid structure.
Assembly: mscorlib (in mscorlib.dll)
This is a convenient static method that you can call to get a new Guid.
The chance that the value of the new Guid will be all zeros or equal to any other Guid is very low. You can determine whether a GUID consists of all zeros by comparing it to Guid.Empty.
The following example creates and displays the values of two Guid objects.
// This code example demonstrates the Guid.NewGuid() method. using System; class Sample { public static void Main() { Guid g; // Create and display the value of two GUIDs. g = Guid.NewGuid(); Console.WriteLine(g); Console.WriteLine(Guid.NewGuid()); } } /* This code example produces the following results: 0f8fad5b-d9cb-469f-a165-70867728950e 7c9e6679-7425-40de-944b-e07fc1f90ae7 */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.