Skip to content

Commit 9d06a1e

Browse files
WilliamAntonRohmBillWagner
authored andcommitted
updating Hashset`1.xml samples for Try .NET (#1533)
* updating for Try .NET * updating for Try .NET
1 parent eb2ec4e commit 9d06a1e

File tree

7 files changed

+152
-156
lines changed
  • snippets/csharp/VS_Snippets_CLR_System
    • system.Collections.Generic.HashSet_Clear/cs
    • system.Collections.Generic.HashSet_ExceptWith/cs
    • system.Collections.Generic.HashSet_RemoveWhere/cs
    • system.Collections.Generic.HashSet_SymmetricExceptWith/cs
    • system.Collections.Generic.HashSet_UnionWith/cs
    • system.Collections.Generic.HashSet_boolMethods/cs

7 files changed

+152
-156
lines changed

snippets/csharp/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_Clear/cs/Program.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class Program
66
{
7-
//<snippet02>
87
static void Main()
98
{
9+
//<snippet02>
1010
HashSet<int> Numbers = new HashSet<int>();
1111

1212
for (int i = 0; i < 10; i++)
@@ -23,21 +23,21 @@ static void Main()
2323
Console.Write("Numbers contains {0} elements: ", Numbers.Count);
2424
DisplaySet(Numbers);
2525

26-
}
27-
/* This example produces output similar to the following:
28-
* Numbers contains 10 elements: { 0 1 2 3 4 5 6 7 8 9 }
29-
* Numbers contains 0 elements: { }
30-
*/
31-
//</snippet02>
32-
33-
private static void DisplaySet(HashSet<int> set)
34-
{
35-
Console.Write("{");
36-
foreach (int i in set)
26+
void DisplaySet(HashSet<int> set)
3727
{
38-
Console.Write(" {0}", i);
28+
Console.Write("{");
29+
foreach (int i in set)
30+
{
31+
Console.Write(" {0}", i);
32+
}
33+
Console.WriteLine(" }");
3934
}
40-
Console.WriteLine(" }");
35+
36+
/* This example produces output similar to the following:
37+
* Numbers contains 10 elements: { 0 1 2 3 4 5 6 7 8 9 }
38+
* Numbers contains 0 elements: { }
39+
*/
40+
//</snippet02>
4141
}
4242
}
4343
//</snippet01>

snippets/csharp/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_ExceptWith/cs/Program.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class Program
66
{
7-
//<snippet02>
87
static void Main()
98
{
9+
//<snippet02>
1010
HashSet<int> lowNumbers = new HashSet<int>();
1111
HashSet<int> highNumbers = new HashSet<int>();
1212

@@ -32,25 +32,23 @@ static void Main()
3232
Console.Write("highNumbers contains {0} elements: ", highNumbers.Count);
3333
DisplaySet(highNumbers);
3434

35-
36-
37-
}
38-
/* This example provides output similar to the following:
39-
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
40-
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
41-
* highNumbers ExceptWith lowNumbers...
42-
* highNumbers contains 4 elements: { 6 7 8 9 }
43-
*/
44-
//</snippet02>
45-
46-
private static void DisplaySet(HashSet<int> set)
47-
{
48-
Console.Write("{");
49-
foreach (int i in set)
35+
void DisplaySet(HashSet<int> set)
5036
{
51-
Console.Write(" {0}", i);
37+
Console.Write("{");
38+
foreach (int i in set)
39+
{
40+
Console.Write(" {0}", i);
41+
}
42+
Console.WriteLine(" }");
5243
}
53-
Console.WriteLine(" }");
44+
45+
/* This example provides output similar to the following:
46+
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
47+
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
48+
* highNumbers ExceptWith lowNumbers...
49+
* highNumbers contains 4 elements: { 6 7 8 9 }
50+
*/
51+
//</snippet02>
5452
}
5553
}
5654
//</snippet01>

snippets/csharp/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_ExceptWith/cs/source2.cs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//<snippet03>
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43

54
class Program
65
{
76
public static void Main()
87
{
8+
//<snippet03>
99
HashSet<string> allVehicles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
1010
List<string> someVehicles = new List<string>();
1111

@@ -64,50 +64,50 @@ public static void Main()
6464
{
6565
Console.WriteLine(vehicle);
6666
}
67-
}
6867

69-
// Predicate to determine vehicle 'coolness'.
70-
private static bool isNotSuperCool(string vehicle)
71-
{
72-
bool superCool = (vehicle == "Helicopters") || (vehicle == "Motorcycles");
68+
// Predicate to determine vehicle 'coolness'.
69+
bool isNotSuperCool(string vehicle)
70+
{
71+
bool superCool = (vehicle == "Helicopters") || (vehicle == "Motorcycles");
7372

74-
return !superCool;
73+
return !superCool;
74+
}
75+
76+
// The program writes the following output to the console.
77+
//
78+
// The current HashSet contains:
79+
//
80+
// Planes
81+
// Trains
82+
// Automobiles
83+
//
84+
// The updated HashSet contains:
85+
//
86+
// Planes
87+
// Trains
88+
// Automobiles
89+
// Ships
90+
// Motorcycles
91+
// Rockets
92+
// Helicopters
93+
// Submarines
94+
//
95+
// The 'All' vehicles set contains everything in 'Some' vechicles list.
96+
//
97+
// The 'All' vehicles set contains 'roCKeTs'
98+
//
99+
// The excepted HashSet contains:
100+
//
101+
// Ships
102+
// Motorcycles
103+
// Rockets
104+
// Helicopters
105+
// Submarines
106+
//
107+
// The super cool vehicles are:
108+
//
109+
// Motorcycles
110+
// Helicopters
111+
//</snippet03>
75112
}
76113
}
77-
78-
// The program writes the following output to the console.
79-
//
80-
// The current HashSet contains:
81-
//
82-
// Planes
83-
// Trains
84-
// Automobiles
85-
//
86-
// The updated HashSet contains:
87-
//
88-
// Planes
89-
// Trains
90-
// Automobiles
91-
// Ships
92-
// Motorcycles
93-
// Rockets
94-
// Helicopters
95-
// Submarines
96-
//
97-
// The 'All' vehicles set contains everything in 'Some' vechicles list.
98-
//
99-
// The 'All' vehicles set contains 'roCKeTs'
100-
//
101-
// The excepted HashSet contains:
102-
//
103-
// Ships
104-
// Motorcycles
105-
// Rockets
106-
// Helicopters
107-
// Submarines
108-
//
109-
// The super cool vehicles are:
110-
//
111-
// Motorcycles
112-
// Helicopters
113-
//</snippet03>
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//<snippet01>
2-
//<snippet02>
32
using System;
43
using System.Collections.Generic;
54

65
class Example
76
{
87
static void Main()
98
{
9+
//<snippet02>
1010
HashSet<int> numbers = new HashSet<int>();
1111

1212
for (int i = 0; i < 20; i++) {
@@ -28,27 +28,28 @@ static void Main()
2828
}
2929
Console.Write("numbers contains {0} elements: ", numbers.Count);
3030
DisplaySet(numbers);
31-
}
3231

33-
private static bool IsOdd(int i)
34-
{
35-
return ((i % 2) == 1);
36-
}
32+
bool IsOdd(int i)
33+
{
34+
return ((i % 2) == 1);
35+
}
3736

38-
private static void DisplaySet(HashSet<int> set)
39-
{
40-
Console.Write("{");
41-
foreach (int i in set)
42-
Console.Write(" {0}", i);
37+
void DisplaySet(HashSet<int> set)
38+
{
39+
Console.Write("{");
40+
foreach (int i in set)
41+
Console.Write(" {0}", i);
42+
43+
Console.WriteLine(" }");
44+
}
4345

44-
Console.WriteLine(" }");
46+
// This example display the following output:
47+
// numbers contains 20 elements: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 }
48+
// numbers contains 10 elements: { 0 2 4 6 8 10 12 14 16 18 }
49+
// numbers contains 9 elements: { 2 4 6 8 10 12 14 16 18 }
50+
// </snippet02>
4551
}
4652
}
47-
// This example display the following output:
48-
// numbers contains 20 elements: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 }
49-
// numbers contains 10 elements: { 0 2 4 6 8 10 12 14 16 18 }
50-
// numbers contains 9 elements: { 2 4 6 8 10 12 14 16 18 }
51-
// </snippet02>
5253
// </snippet01>
5354

5455

snippets/csharp/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_SymmetricExceptWith/cs/Program.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class Program
66
{
7-
//<snippet02>
87
static void Main()
98
{
9+
//<snippet02>
1010
HashSet<int> lowNumbers = new HashSet<int>();
1111
HashSet<int> highNumbers = new HashSet<int>();
1212

@@ -32,25 +32,23 @@ static void Main()
3232
Console.Write("lowNumbers contains {0} elements: ", lowNumbers.Count);
3333
DisplaySet(lowNumbers);
3434

35-
36-
37-
}
38-
/* This example provides output similar to the following:
39-
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
40-
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
41-
* lowNumbers SymmetricExceptWith highNumbers...
42-
* lowNumbers contains 7 elements: { 0 1 2 8 7 6 9 }
43-
*/
44-
//</snippet02>
45-
46-
private static void DisplaySet(HashSet<int> set)
47-
{
48-
Console.Write("{");
49-
foreach (int i in set)
35+
void DisplaySet(HashSet<int> set)
5036
{
51-
Console.Write(" {0}", i);
37+
Console.Write("{");
38+
foreach (int i in set)
39+
{
40+
Console.Write(" {0}", i);
41+
}
42+
Console.WriteLine(" }");
5243
}
53-
Console.WriteLine(" }");
44+
45+
/* This example provides output similar to the following:
46+
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
47+
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
48+
* lowNumbers SymmetricExceptWith highNumbers...
49+
* lowNumbers contains 7 elements: { 0 1 2 8 7 6 9 }
50+
*/
51+
//</snippet02>
5452
}
5553
}
5654
//</snippet01>

snippets/csharp/VS_Snippets_CLR_System/system.Collections.Generic.HashSet_UnionWith/cs/Program.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
//<snippet01>
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43

54
class Program
65
{
7-
//<snippet02>
86
static void Main()
97
{
8+
//<snippet01>
109
//<snippet03>
1110
HashSet<int> evenNumbers = new HashSet<int>();
1211
HashSet<int> oddNumbers = new HashSet<int>();
@@ -35,23 +34,22 @@ static void Main()
3534
Console.Write("numbers contains {0} elements: ", numbers.Count);
3635
DisplaySet(numbers);
3736

38-
}
39-
//</snippet02>
40-
41-
private static void DisplaySet(HashSet<int> set)
42-
{
43-
Console.Write("{");
44-
foreach (int i in set)
37+
void DisplaySet(HashSet<int> set)
4538
{
46-
Console.Write(" {0}", i);
39+
Console.Write("{");
40+
foreach (int i in set)
41+
{
42+
Console.Write(" {0}", i);
43+
}
44+
Console.WriteLine(" }");
4745
}
48-
Console.WriteLine(" }");
46+
47+
/* This example produces output similar to the following:
48+
* evenNumbers contains 5 elements: { 0 2 4 6 8 }
49+
* oddNumbers contains 5 elements: { 1 3 5 7 9 }
50+
* numbers UnionWith oddNumbers...
51+
* numbers contains 10 elements: { 0 2 4 6 8 1 3 5 7 9 }
52+
*/
53+
//</snippet01>
4954
}
5055
}
51-
/* This example produces output similar to the following:
52-
* evenNumbers contains 5 elements: { 0 2 4 6 8 }
53-
* oddNumbers contains 5 elements: { 1 3 5 7 9 }
54-
* numbers UnionWith oddNumbers...
55-
* numbers contains 10 elements: { 0 2 4 6 8 1 3 5 7 9 }
56-
*/
57-
//</snippet01>

0 commit comments

Comments
 (0)