Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Guid.NewGuid Method

Initializes a new instance of the Guid class.

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

'Declaration
<SecuritySafeCriticalAttribute> _
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.

There is a very low probability that the value of the new Guid is all zeroes or equal to any other Guid. 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.

Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim g As Guid
      ' Create and display the value of two GUIDs.
      g = Guid.NewGuid()
      outputBlock.Text &= g.ToString() & vbCrLf
      outputBlock.Text &= Guid.NewGuid().ToString() & vbCrLf
   End Sub 
End Class 
'
'This code example produces the following results:
'
'0f8fad5b-d9cb-469f-a165-70867728950e
'7c9e6679-7425-40de-944b-e07fc1f90ae7
'


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft