LoginSignup
35
33

More than 5 years have passed since last update.

GUIDを生成する。

Last updated at Posted at 2012-02-10

世界で重複することがない、ユニークな128bit(16byte)のランダムな数値であるGUID値を生成する。

guid.cs
using System;               // Guid,Console

class GuidSample {
    public static void Main(string[] args) {
        String id = Guid.NewGuid().ToString("N");
        Console.WriteLine(id);
    }
}

実行結果

$ guid.exe
4b1d4ca7f22b49e284753a034e673629

Guid.ToString()の整形方法

  • "N" : 32桁 ⇒ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  • "D" : ハイフンで区切られた32桁 ⇒ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  • "B" : 中かっこで囲まれ、ハイフンで区切られた32桁 ⇒ {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
  • "P" : 丸かっこで囲まれ、ハイフンで区切られた32桁 ⇒ (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

--

参考

35
33
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
33