本文整理匯總了C#中System.Guid.Guid構造函數的典型用法代碼示例。如果您正苦於以下問題:C# Guid構造函數的具體用法?C# Guid怎麽用?C# Guid使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Guid
的用法示例。
在下文中一共展示了Guid構造函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: foreach
string[] guidStrings = { "ca761232ed4211cebacd00aa0057b223",
"CA761232-ED42-11CE-BACD-00AA0057B223",
"{CA761232-ED42-11CE-BACD-00AA0057B223}",
"(CA761232-ED42-11CE-BACD-00AA0057B223)",
"{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}" };
foreach (var guidString in guidStrings)
{
var guid = new Guid(guidString);
Console.WriteLine($"Original string: {guidString}");
Console.WriteLine($"Guid: {guid}");
Console.WriteLine();
}
輸出:
Original string: ca761232ed4211cebacd00aa0057b223 Guid: ca761232-ed42-11ce-bacd-00aa0057b223 Original string: CA761232-ED42-11CE-BACD-00AA0057B223 Guid: ca761232-ed42-11ce-bacd-00aa0057b223 Original string: {CA761232-ED42-11CE-BACD-00AA0057B223} Guid: ca761232-ed42-11ce-bacd-00aa0057b223 Original string: (CA761232-ED42-11CE-BACD-00AA0057B223) Guid: ca761232-ed42-11ce-bacd-00aa0057b223 Original string: {0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}} Guid: ca761232-ed42-11ce-bacd-00aa0057b223
示例2: Guid
var g = new Guid(0xA, 0xB, 0xC,
new Byte[] { 0, 1, 2, 3, 4, 5, 6, 7 } );
Console.WriteLine($"{g:B}");
輸出:
{0000000a-000b-000c-0001-020304050607}