Export (0) Print
Expand All

Guid.NewGuid Method

Initializes a new instance of the Guid class.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static Guid NewGuid ()
public static Guid NewGuid ()
public static function NewGuid () : Guid
Not applicable.

Return Value

A new Guid object.

This is a convenient static method that you can call to get a new Guid.

There is a very low probability that the value of the new Guid is all zeroes or equal to any other Guid.

The following code example creates and displays the value 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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft