-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
85 lines (71 loc) · 2.85 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
namespace GUIDsWithDifferentFormats
{
/// <summary>
/// https://docs.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=net-6.0
/// https://stackoverflow.com/questions/7775439/is-the-format-of-guid-always-the-same/7775466#7775466
/// </summary>
class Program
{
static void Main(string[] args)
{
Guid currentGuid = Guid.NewGuid();
Console.WriteLine($"Default Guid Value:{currentGuid}");
Console.WriteLine();
Console.WriteLine("----------------------Formatting--------------------------------");
Console.WriteLine($"D:32 digits separated by hyphens:{currentGuid.ToString("D")}");
Console.WriteLine($"N:32 digits:{currentGuid.ToString("N")}");
Console.WriteLine($"B:32 digits separated by hyphens, enclosed in braces:{currentGuid.ToString("B")}");
Console.WriteLine($"P:32 digits separated by hyphens, enclosed in parentheses:{currentGuid.ToString("P")}");
Console.WriteLine($"X:Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:{currentGuid.ToString("X")}");
Console.WriteLine();
Console.WriteLine("----------------------Parsing-----------------------------------");
try
{
Guid.ParseExact(currentGuid.ToString("D"), "D");
Console.WriteLine($"{currentGuid.ToString("D")} is parsed the guid type.");
}
catch
{
Console.WriteLine("Failed1");
}
try
{
Guid.ParseExact(currentGuid.ToString("N"), "N");
Console.WriteLine($"{currentGuid.ToString("N")} is parsed the guid type.");
}
catch (Exception)
{
Console.WriteLine("Failed3");
}
try
{
Guid.ParseExact(currentGuid.ToString("B"), "B");
Console.WriteLine($"{currentGuid.ToString("B")} is parsed the guid type.");
}
catch
{
Console.WriteLine("Failed4");
}
try
{
Guid.ParseExact(currentGuid.ToString("P"), "P");
Console.WriteLine($"{currentGuid.ToString("P")} is parsed the guid type.");
}
catch
{
Console.WriteLine("Failed5");
}
try
{
Guid.ParseExact(currentGuid.ToString("X"), "X");
Console.WriteLine($"{currentGuid.ToString("X")} is parsed the guid type.");
}
catch
{
Console.WriteLine("Failed6");
}
Console.ReadLine();
}
}
}