C# 通用唯一識別碼 (GUID)

來源:互聯網
上載者:User

標籤:style   http   ar   os   使用   sp   for   strong   on   

一 C#  通用唯一識別碼 (GUID)

Represents a globally unique identifier (GUID).

To browse the .NET Framework source code for this type, see the Reference Source.

Namespace:  System

Assembly:  mscorlib (in mscorlib.dll)

GUID 是一個 128 位整數(16 位元組),可用於所有需要唯一識別碼的電腦和網路。 此標識符重複的可能性非常小。

二 GUID使用樣本(C#)

private string getGUID(int type) 

System.Guid guid = new Guid(); 
guid = Guid.NewGuid(); 
string stmp= "";

if(type==0)

{

guid.ToString("N"); 

}

else if(type==1)

{

guid.ToString("D"); 

}

else if(type==2)

{

guid.ToString("B"); 

}

else if(type==3)

{

guid.ToString("P"); 

}


return stmp; 

格式說明符 
傳回值的格式 

N 32位: 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
如:e92b8e30a6e541f6a6b9188230a23dd2 

D 由連字號分隔的32位元字: 
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
如:e92b8e30-a6e5-41f6-a6b9-188230a23dd2 

B 括在大括弧中、由連字號分隔的32位元字: 
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 
如:{e92b8e30-a6e5-41f6-a6b9-188230a23dd2} 

P 括在圓括弧中、由連字號分隔的32位元字: 
(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) 
如:(e92b8e30-a6e5-41f6-a6b9-188230a23dd2)

C# 通用唯一識別碼 (GUID)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.