Skip to content

Commit 7b12611

Browse files
WilliamAntonRohmmairaw
authored andcommitted
updating Guid.xml samples for Try .NET (#1654)
* updating for Try .NET * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.ctor/cs/ctor1.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.ctor/cs/ctor2.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.empty/cs/empty.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/parseex1.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/parseexactex1.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/tryparseexactex1.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.tobytearray/cs/tobytearray3.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.tobytearray/cs/tobytearray3.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.tobytearray/cs/tobytearray3.cs Co-Authored-By: Youssef Victor <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.ctor/cs/ctor1.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.ctor/cs/ctor2.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.empty/cs/empty.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.empty/cs/empty.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.empty/cs/empty.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.empty/cs/empty.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/tryparseexactex1.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/tryparseexactex1.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.tobytearray/cs/tobytearray3.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.tobytearray/cs/tobytearray3.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.tobytearray/cs/tobytearray3.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.newguid/cs/ng.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.newguid/cs/ng.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/parseex1.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/parseexactex1.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/tryparseex1.cs Co-Authored-By: Maira Wenzel <[email protected]> * Update snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/tryparseexactex1.cs Co-Authored-By: Maira Wenzel <[email protected]> * per review comments * per review comments * per review comments * per review comments
1 parent d71c49c commit 7b12611

File tree

9 files changed

+126
-120
lines changed

9 files changed

+126
-120
lines changed

snippets/csharp/VS_Snippets_CLR_System/system.guid.ctor/cs/ctor1.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
// <Snippet1>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet1>
88
string[] guidStrings = { "ca761232ed4211cebacd00aa0057b223",
99
"CA761232-ED42-11CE-BACD-00AA0057B223",
1010
"{CA761232-ED42-11CE-BACD-00AA0057B223}",
1111
"(CA761232-ED42-11CE-BACD-00AA0057B223)",
1212
"{0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}" };
1313
foreach (var guidString in guidStrings) {
1414
Guid guid = new Guid(guidString);
15-
Console.WriteLine("Original string: {0}", guidString);
16-
Console.WriteLine("Guid: {0}", guid);
15+
Console.WriteLine($"Original string: {guidString}");
16+
Console.WriteLine($"Guid: {guid}");
1717
Console.WriteLine();
1818
}
19+
20+
// The example displays the following output:
21+
// Original string: ca761232ed4211cebacd00aa0057b223
22+
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
23+
//
24+
// Original string: CA761232-ED42-11CE-BACD-00AA0057B223
25+
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
26+
//
27+
// Original string: {CA761232-ED42-11CE-BACD-00AA0057B223}
28+
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
29+
//
30+
// Original string: (CA761232-ED42-11CE-BACD-00AA0057B223)
31+
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
32+
//
33+
// Original string: {0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}
34+
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
35+
// </Snippet1>
1936
}
2037
}
21-
// The example displays the following output:
22-
// Original string: ca761232ed4211cebacd00aa0057b223
23-
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
24-
//
25-
// Original string: CA761232-ED42-11CE-BACD-00AA0057B223
26-
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
27-
//
28-
// Original string: {CA761232-ED42-11CE-BACD-00AA0057B223}
29-
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
30-
//
31-
// Original string: (CA761232-ED42-11CE-BACD-00AA0057B223)
32-
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
33-
//
34-
// Original string: {0xCA761232, 0xED42, 0x11CE, {0xBA, 0xCD, 0x00, 0xAA, 0x00, 0x57, 0xB2, 0x23}}
35-
// Guid: ca761232-ed42-11ce-bacd-00aa0057b223
36-
// </Snippet1>

snippets/csharp/VS_Snippets_CLR_System/system.guid.ctor/cs/ctor2.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
// <Snippet2>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
8-
Guid g = new Guid(0xA, 0xB, 0xC,
7+
// <Snippet2>
8+
var g = new Guid(0xA, 0xB, 0xC,
99
new Byte[] { 0, 1, 2, 3, 4, 5, 6, 7 } );
10-
Console.WriteLine("{0:B}", g);
10+
Console.WriteLine($"{g:B}");
11+
12+
// The example displays the following output:
13+
// {0000000a-000b-000c-0001-020304050607}
14+
// </Snippet2>
1115
}
1216
}
13-
// The example displays the following output:
14-
// {0000000a-000b-000c-0001-020304050607}
15-
// </Snippet2>

snippets/csharp/VS_Snippets_CLR_System/system.guid.empty/cs/empty.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
// <Snippet1>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet1>
88
// Create a GUID and determine whether it consists of all zeros.
9-
Guid guid1 = Guid.NewGuid();
9+
var guid1 = Guid.NewGuid();
1010
Console.WriteLine(guid1);
11-
Console.WriteLine("Empty: {0}\n", guid1 == Guid.Empty);
11+
Console.WriteLine($"Empty: {guid1 == Guid.Empty}\n");
1212

1313
// Create a GUID with all zeros and compare it to Empty.
14-
Byte[] bytes = new Byte[16];
15-
Guid guid2 = new Guid(bytes);
14+
var bytes = new Byte[16];
15+
var guid2 = new Guid(bytes);
1616
Console.WriteLine(guid2);
17-
Console.WriteLine("Empty: {0}", guid2 == Guid.Empty);
17+
Console.WriteLine($"Empty: {guid2 == Guid.Empty}");
18+
19+
// The example displays output like the following:
20+
// 11c43ee8-b9d3-4e51-b73f-bd9dda66e29c
21+
// Empty: False
22+
//
23+
// 00000000-0000-0000-0000-000000000000
24+
// Empty: True
25+
// </Snippet1>
1826
}
1927
}
20-
// The example displays output like the following:
21-
// 11c43ee8-b9d3-4e51-b73f-bd9dda66e29c
22-
// Empty: False
23-
//
24-
// 00000000-0000-0000-0000-000000000000
25-
// Empty: True
26-
// </Snippet1>
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
//<snippet1>
2-
// This code example demonstrates the Guid.NewGuid() method.
1+
// This code example demonstrates the Guid.NewGuid() method.
32

43
using System;
54

65
class Sample
76
{
87
public static void Main()
98
{
10-
Guid g;
9+
//<snippet1>
1110
// Create and display the value of two GUIDs.
12-
g = Guid.NewGuid();
11+
var g = Guid.NewGuid();
1312
Console.WriteLine(g);
1413
Console.WriteLine(Guid.NewGuid());
14+
15+
// This code example produces a result similar to the following:
16+
17+
// 0f8fad5b-d9cb-469f-a165-70867728950e
18+
// 7c9e6679-7425-40de-944b-e07fc1f90ae7
19+
//</snippet1>
1520
}
1621
}
17-
18-
/*
19-
This code example produces the following results:
20-
21-
0f8fad5b-d9cb-469f-a165-70867728950e
22-
7c9e6679-7425-40de-944b-e07fc1f90ae7
23-
24-
*/
25-
//</snippet1>

snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/parseex1.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// <Snippet3>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
8-
Guid originalGuid = Guid.NewGuid();
7+
// <Snippet3>
8+
var originalGuid = Guid.NewGuid();
99
// Create an array of string representations of the GUID.
1010
string[] stringGuids = { originalGuid.ToString("B"),
1111
originalGuid.ToString("D"),
@@ -14,20 +14,22 @@ public static void Main()
1414
// Parse each string representation.
1515
foreach (var stringGuid in stringGuids) {
1616
try {
17-
Guid newGuid = Guid.Parse(stringGuid);
18-
Console.WriteLine("Converted {0} to a Guid", stringGuid);
17+
var newGuid = Guid.Parse(stringGuid);
18+
Console.WriteLine($"Converted {stringGuid} to a Guid");
1919
}
2020
catch (ArgumentNullException) {
2121
Console.WriteLine("The string to be parsed is null.");
2222
}
2323
catch (FormatException) {
24-
Console.WriteLine("Bad format: {0}", stringGuid);
24+
Console.WriteLine($"Bad format: {stringGuid}");
2525
}
2626
}
27+
28+
// The example displays output similar to the following:
29+
//
30+
// Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
31+
// Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
32+
// Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
33+
// </Snippet3>
2734
}
2835
}
29-
// The example displays the following output:
30-
// Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
31-
// Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
32-
// Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
33-
// </Snippet3>

snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/parseexactex1.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1-
// <Snippet4>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet4>
88
// Define an array of all format specifiers.
99
string[] formats = { "N", "D", "B", "P", "X" };
10-
Guid guid = Guid.NewGuid();
10+
var guid = Guid.NewGuid();
1111
// Create an array of valid Guid string representations.
12-
string[] stringGuids = new string[formats.Length];
12+
var stringGuids = new string[formats.Length];
1313
for (int ctr = 0; ctr < formats.Length; ctr++)
1414
stringGuids[ctr] = guid.ToString(formats[ctr]);
1515

1616
// Parse the strings in the array using the "B" format specifier.
1717
foreach (var stringGuid in stringGuids) {
1818
try {
19-
Guid newGuid = Guid.ParseExact(stringGuid, "B");
20-
Console.WriteLine("Successfully parsed {0}", stringGuid);
19+
var newGuid = Guid.ParseExact(stringGuid, "B");
20+
Console.WriteLine($"Successfully parsed {stringGuid}");
2121
}
2222
catch (ArgumentNullException) {
2323
Console.WriteLine("The string to be parsed is null.");
2424
}
2525
catch (FormatException) {
26-
Console.WriteLine("Bad Format: {0}", stringGuid);
26+
Console.WriteLine($"Bad Format: {stringGuid}");
2727
}
2828
}
29+
30+
// The example displays output similar to the following:
31+
//
32+
// Bad Format: eb5c8c7d187a44e68afb81e854c39457
33+
// Bad Format: eb5c8c7d-187a-44e6-8afb-81e854c39457
34+
// Successfully parsed {eb5c8c7d-187a-44e6-8afb-81e854c39457}
35+
// Bad Format: (eb5c8c7d-187a-44e6-8afb-81e854c39457)
36+
// Bad Format: {0xeb5c8c7d,0x187a,0x44e6,{0x8a,0xfb,0x81,0xe8,0x54,0xc3,0x94,0x57}}
37+
// </Snippet4>
2938
}
3039
}
31-
// The example displays the following output:
32-
// Bad Format: eb5c8c7d187a44e68afb81e854c39457
33-
// Bad Format: eb5c8c7d-187a-44e6-8afb-81e854c39457
34-
// Successfully parsed {eb5c8c7d-187a-44e6-8afb-81e854c39457}
35-
// Bad Format: (eb5c8c7d-187a-44e6-8afb-81e854c39457)
36-
// Bad Format: {0xeb5c8c7d,0x187a,0x44e6,{0x8a,0xfb,0x81,0xe8,0x54,0xc3,0x94,0x57}}
37-
// </Snippet4>
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
// <Snippet2>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
8-
Guid originalGuid = Guid.NewGuid();
7+
// <Snippet2>
8+
var originalGuid = Guid.NewGuid();
99
// Create an array of string representations of the GUID.
1010
string[] stringGuids = { originalGuid.ToString("B"),
1111
originalGuid.ToString("D"),
1212
originalGuid.ToString("X") };
1313

1414
// Parse each string representation.
15-
Guid newGuid;
1615
foreach (var stringGuid in stringGuids) {
17-
if (Guid.TryParse(stringGuid, out newGuid))
18-
Console.WriteLine("Converted {0} to a Guid", stringGuid);
16+
if (Guid.TryParse(stringGuid, out var newGuid))
17+
Console.WriteLine($"Converted {stringGuid} to a Guid");
1918
else
20-
Console.WriteLine("Unable to convert {0} to a Guid",
21-
stringGuid);
19+
Console.WriteLine($"Unable to convert {stringGuid} to a Guid");
2220
}
21+
22+
// The example displays output similar to the following:
23+
//
24+
// Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
25+
// Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
26+
// Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
27+
// </Snippet2>
2328
}
2429
}
25-
// The example displays the following output:
26-
// Converted {81a130d2-502f-4cf1-a376-63edeb000e9f} to a Guid
27-
// Converted 81a130d2-502f-4cf1-a376-63edeb000e9f to a Guid
28-
// Converted {0x81a130d2,0x502f,0x4cf1,{0xa3,0x76,0x63,0xed,0xeb,0x00,0x0e,0x9f}} to a Guid
29-
// </Snippet2>

snippets/csharp/VS_Snippets_CLR_System/system.guid.parse/cs/tryparseexactex1.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
// <Snippet5>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
7+
// <Snippet5>
88
// Define an array of all format specifiers.
99
string[] formats = { "N", "D", "B", "P", "X" };
10-
Guid guid = Guid.NewGuid();
10+
var guid = Guid.NewGuid();
1111
// Create an array of valid Guid string representations.
12-
string[] stringGuids = new string[formats.Length];
12+
var stringGuids = new string[formats.Length];
1313
for (int ctr = 0; ctr < formats.Length; ctr++)
1414
stringGuids[ctr] = guid.ToString(formats[ctr]);
1515

1616
// Parse the strings in the array using the "B" format specifier.
1717
foreach (var stringGuid in stringGuids) {
18-
Guid newGuid;
19-
if (Guid.TryParseExact(stringGuid, "B", out newGuid))
20-
Console.WriteLine("Successfully parsed {0}", stringGuid);
18+
if (Guid.TryParseExact(stringGuid, "B", out var newGuid))
19+
Console.WriteLine($"Successfully parsed {stringGuid}");
2120
else
22-
Console.WriteLine("Unable to parse '{0}'", stringGuid);
21+
Console.WriteLine($"Unable to parse '{stringGuid}'");
2322
}
23+
24+
// The example displays output similar to the following:
25+
//
26+
// Unable to parse 'c0fb150f6bf344df984a3a0611ae5e4a'
27+
// Unable to parse 'c0fb150f-6bf3-44df-984a-3a0611ae5e4a'
28+
// Successfully parsed {c0fb150f-6bf3-44df-984a-3a0611ae5e4a}
29+
// Unable to parse '(c0fb150f-6bf3-44df-984a-3a0611ae5e4a)'
30+
// Unable to parse '{0xc0fb150f,0x6bf3,0x44df,{0x98,0x4a,0x3a,0x06,0x11,0xae,0x5e,0x4a}}'
31+
// </Snippet5>
2432
}
2533
}
26-
// The example displays the following output:
27-
// Unable to parse 'c0fb150f6bf344df984a3a0611ae5e4a'
28-
// Unable to parse 'c0fb150f-6bf3-44df-984a-3a0611ae5e4a'
29-
// Successfully parsed {c0fb150f-6bf3-44df-984a-3a0611ae5e4a}
30-
// Unable to parse '(c0fb150f-6bf3-44df-984a-3a0611ae5e4a)'
31-
// Unable to parse '{0xc0fb150f,0x6bf3,0x44df,{0x98,0x4a,0x3a,0x06,0x11,0xae,0x5e,0x4a}}'
32-
// </Snippet5>

snippets/csharp/VS_Snippets_CLR_System/system.guid.tobytearray/cs/tobytearray3.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
// <Snippet1>
2-
using System;
1+
using System;
32

43
public class Example
54
{
65
public static void Main()
76
{
8-
Guid guid = Guid.NewGuid();
9-
Console.WriteLine("Guid: {0}", guid);
10-
Byte[] bytes = guid.ToByteArray();
7+
// <Snippet1>
8+
var guid = Guid.NewGuid();
9+
Console.WriteLine($"Guid: {guid}");
10+
var bytes = guid.ToByteArray();
1111
foreach (var byt in bytes)
12-
Console.Write("{0:X2} ", byt);
12+
Console.Write($"{byt:X2} ");
1313

1414
Console.WriteLine();
15-
Guid guid2 = new Guid(bytes);
16-
Console.WriteLine("Guid: {0} (Same as First Guid: {1})", guid2, guid2.Equals(guid));
15+
var guid2 = new Guid(bytes);
16+
Console.WriteLine($"Guid: {guid2} (Same as First Guid: {guid2.Equals(guid)})");
17+
18+
// The example displays output similar to the following:
19+
//
20+
// Guid: 35918bc9-196d-40ea-9779-889d79b753f0
21+
// C9 8B 91 35 6D 19 EA 40 97 79 88 9D 79 B7 53 F0
22+
// Guid: 35918bc9-196d-40ea-9779-889d79b753f0 (Same as First Guid: True)
23+
// </Snippet1>
1724
}
1825
}
19-
// The example displays the following output:
20-
// Guid: 35918bc9-196d-40ea-9779-889d79b753f0
21-
// C9 8B 91 35 6D 19 EA 40 97 79 88 9D 79 B7 53 F0
22-
// Guid: 35918bc9-196d-40ea-9779-889d79b753f0 (Same as First Guid: True)
23-
// </Snippet1>

0 commit comments

Comments
 (0)