6 out of 9 rated this helpful - Rate this topic

Guid.NewGuid Method

Initializes a new instance of the Guid structure.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
'Declaration
Public Shared Function NewGuid As Guid

Return Value

Type: System.Guid
A new GUID object.

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 code example creates and displays the values of two Guid objects.

' This code example demonstrates the Guid.NewGuid() method. 
Imports System

Class Sample
    Public Shared Sub Main() 
        Dim g As Guid
' Create and display the value of two GUIDs.
        g = Guid.NewGuid()
        Console.WriteLine(g)
        Console.WriteLine(Guid.NewGuid())
    End Sub 'Main
End Class 'Sample

'This code example produces the following results: 

'0f8fad5b-d9cb-469f-a165-70867728950e 
'7c9e6679-7425-40de-944b-e07fc1f90ae7 
'

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.