Guid.NewGuid Method

Definition

初始化 Guid 结构的新实例。Initializes a new instance of the Guid structure.

public:
 static Guid NewGuid();
public static Guid NewGuid ();
static member NewGuid : unit -> Guid
Public Shared Function NewGuid () As Guid

Returns

Guid

一个新的 GUID 对象。A new GUID object.

Examples

下面的代码示例创建并显示两个 Guid 对象的值。The following code example creates and displays the values of two Guid objects.

// Create and display the value of two GUIDs.
Guid g = Guid.NewGuid();
Console.WriteLine(g);
Console.WriteLine(Guid.NewGuid());

// This code example produces a result similar to the following:

// 0f8fad5b-d9cb-469f-a165-70867728950e
// 7c9e6679-7425-40de-944b-e07fc1f90ae7
' This code example demonstrates the Guid.NewGuid() method.
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
End Class
'
'This code example produces the following results:
'
'0f8fad5b-d9cb-469f-a165-70867728950e
'7c9e6679-7425-40de-944b-e07fc1f90ae7
'

Remarks

这是一个方便的 static 方法,你可以调用它来获取新的 GuidThis is a convenient static method that you can call to get a new Guid. 方法包装对 Windows CoCreateGuid函数的调用。The method wraps a call to the Windows CoCreateGuid function. 保证返回的 Guid 不等于 Guid.EmptyThe returned Guid is guaranteed to not equal Guid.Empty.

Applies to