Home > Article > Backend Development > asp.net System.Guid ToString five formats
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
##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: 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:
##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(); } } }
## Several formats of Guid.NewGuid().ToString()
1. Guid.NewGuid().ToString("N") The result is:38bddf48f43c48588e0d78761eaa1ce6
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:
For more articles related to the five formats of asp.net System.Guid ToString, please pay attention to the PHP Chinese website!