Home  >  Article  >  Backend Development  >  asp.net System.Guid ToString five formats

asp.net System.Guid ToString five formats

高洛峰
高洛峰Original
2017-02-20 17:06:051174browse

This article mainly introduces the five formats of asp.net System.Guid ToString. Friends in need can refer to it

Reference: https://msdn.microsoft.com/en-us/library/ 97af8hh4.aspx

asp.net System.Guid ToString五种格式

##Test code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GuidToString
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(" -->" + System.Guid.NewGuid().ToString());
      Console.WriteLine("N-->" + System.Guid.NewGuid().ToString("N"));
      Console.WriteLine("D-->" + System.Guid.NewGuid().ToString("D"));
      Console.WriteLine("B-->" + System.Guid.NewGuid().ToString("B"));
      Console.WriteLine("P-->" + System.Guid.NewGuid().ToString("P"));
      Console.WriteLine("X-->" + System.Guid.NewGuid().ToString("X"));
      Console.ReadKey();
    }
  }
}

Test result:

asp.net System.Guid ToString五种格式

Note: Only N, D, B, P, and ##The format string can only be "D", "d", "N", "n", "P", "p", "B", "b", "X" or "x".

Exception:

asp.net System.Guid ToString五种格式

##The following are normal:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GuidToString
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(" -->" + System.Guid.NewGuid().ToString());
      Console.WriteLine(" -->" + System.Guid.NewGuid().ToString(""));
      Console.WriteLine("N-->" + System.Guid.NewGuid().ToString("N"));
      Console.WriteLine("n-->" + System.Guid.NewGuid().ToString("n"));
      Console.WriteLine("D-->" + System.Guid.NewGuid().ToString("D"));
      Console.WriteLine("d-->" + System.Guid.NewGuid().ToString("d"));
      Console.WriteLine("B-->" + System.Guid.NewGuid().ToString("B"));
      Console.WriteLine("b-->" + System.Guid.NewGuid().ToString("b"));
      Console.WriteLine("P-->" + System.Guid.NewGuid().ToString("P"));
      Console.WriteLine("p-->" + System.Guid.NewGuid().ToString("p"));
      Console.WriteLine("X-->" + System.Guid.NewGuid().ToString("X"));
      Console.WriteLine("x-->" + System.Guid.NewGuid().ToString("x"));
      Console.ReadKey();
    }
  }
}

asp.net System.Guid ToString五种格式

## Several formats of Guid.NewGuid().ToString()

1. Guid.NewGuid().ToString("N") The result is:

38bddf48f43c48588e0d78761eaa1ce6asp.net System.Guid ToString五种格式

2. Guid.NewGuid().ToString("D") The result is:

57d99d89-caab-482a-a0e9-a0a803eed3ba3. Guid.NewGuid() .ToString("B") The result is:

{09f140d5-af72-44ba-a763-c861304b46f8}


4. Guid.NewGuid().ToString("P") The result is:

(778406c2-efff-4262-ab03-70a77d09c2b5)


For more articles related to the five formats of asp.net System.Guid ToString, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn