Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

GUIDを生成する。

More than 5 years have passed since last update.

世界で重複することがない、ユニークな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)

--

参考

redtower
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away