Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class Program
{
//<snippet02>
static void Main()
{
//<snippet02>
HashSet<int> Numbers = new HashSet<int>();

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

}
/* This example produces output similar to the following:
* Numbers contains 10 elements: { 0 1 2 3 4 5 6 7 8 9 }
* Numbers contains 0 elements: { }
*/
//</snippet02>

private static void DisplaySet(HashSet<int> set)
{
Console.Write("{");
foreach (int i in set)
void DisplaySet(HashSet<int> set)
{
Console.Write(" {0}", i);
Console.Write("{");
foreach (int i in set)
{
Console.Write(" {0}", i);
}
Console.WriteLine(" }");
}
Console.WriteLine(" }");

/* This example produces output similar to the following:
* Numbers contains 10 elements: { 0 1 2 3 4 5 6 7 8 9 }
* Numbers contains 0 elements: { }
*/
//</snippet02>
}
}
//</snippet01>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class Program
{
//<snippet02>
static void Main()
{
//<snippet02>
HashSet<int> lowNumbers = new HashSet<int>();
HashSet<int> highNumbers = new HashSet<int>();

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



}
/* This example provides output similar to the following:
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
* highNumbers ExceptWith lowNumbers...
* highNumbers contains 4 elements: { 6 7 8 9 }
*/
//</snippet02>

private static void DisplaySet(HashSet<int> set)
{
Console.Write("{");
foreach (int i in set)
void DisplaySet(HashSet<int> set)
{
Console.Write(" {0}", i);
Console.Write("{");
foreach (int i in set)
{
Console.Write(" {0}", i);
}
Console.WriteLine(" }");
}
Console.WriteLine(" }");

/* This example provides output similar to the following:
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
* highNumbers ExceptWith lowNumbers...
* highNumbers contains 4 elements: { 6 7 8 9 }
*/
//</snippet02>
}
}
//</snippet01>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//<snippet03>
using System;
using System;
using System.Collections.Generic;

class Program
{
public static void Main()
{
//<snippet03>
HashSet<string> allVehicles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
List<string> someVehicles = new List<string>();

Expand Down Expand Up @@ -64,50 +64,50 @@ public static void Main()
{
Console.WriteLine(vehicle);
}
}

// Predicate to determine vehicle 'coolness'.
private static bool isNotSuperCool(string vehicle)
{
bool superCool = (vehicle == "Helicopters") || (vehicle == "Motorcycles");
// Predicate to determine vehicle 'coolness'.
bool isNotSuperCool(string vehicle)
{
bool superCool = (vehicle == "Helicopters") || (vehicle == "Motorcycles");

return !superCool;
return !superCool;
}

// The program writes the following output to the console.
//
// The current HashSet contains:
//
// Planes
// Trains
// Automobiles
//
// The updated HashSet contains:
//
// Planes
// Trains
// Automobiles
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The 'All' vehicles set contains everything in 'Some' vechicles list.
//
// The 'All' vehicles set contains 'roCKeTs'
//
// The excepted HashSet contains:
//
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The super cool vehicles are:
//
// Motorcycles
// Helicopters
//</snippet03>
}
}

// The program writes the following output to the console.
//
// The current HashSet contains:
//
// Planes
// Trains
// Automobiles
//
// The updated HashSet contains:
//
// Planes
// Trains
// Automobiles
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The 'All' vehicles set contains everything in 'Some' vechicles list.
//
// The 'All' vehicles set contains 'roCKeTs'
//
// The excepted HashSet contains:
//
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The super cool vehicles are:
//
// Motorcycles
// Helicopters
//</snippet03>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//<snippet01>
//<snippet02>
using System;
using System.Collections.Generic;

class Example
{
static void Main()
{
//<snippet02>
HashSet<int> numbers = new HashSet<int>();

for (int i = 0; i < 20; i++) {
Expand All @@ -28,27 +28,28 @@ static void Main()
}
Console.Write("numbers contains {0} elements: ", numbers.Count);
DisplaySet(numbers);
}

private static bool IsOdd(int i)
{
return ((i % 2) == 1);
}
bool IsOdd(int i)
{
return ((i % 2) == 1);
}

private static void DisplaySet(HashSet<int> set)
{
Console.Write("{");
foreach (int i in set)
Console.Write(" {0}", i);
void DisplaySet(HashSet<int> set)
{
Console.Write("{");
foreach (int i in set)
Console.Write(" {0}", i);

Console.WriteLine(" }");
}

Console.WriteLine(" }");
// This example display the following output:
// numbers contains 20 elements: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 }
// numbers contains 10 elements: { 0 2 4 6 8 10 12 14 16 18 }
// numbers contains 9 elements: { 2 4 6 8 10 12 14 16 18 }
// </snippet02>
}
}
// This example display the following output:
// numbers contains 20 elements: { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 }
// numbers contains 10 elements: { 0 2 4 6 8 10 12 14 16 18 }
// numbers contains 9 elements: { 2 4 6 8 10 12 14 16 18 }
// </snippet02>
// </snippet01>


Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

class Program
{
//<snippet02>
static void Main()
{
//<snippet02>
HashSet<int> lowNumbers = new HashSet<int>();
HashSet<int> highNumbers = new HashSet<int>();

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



}
/* This example provides output similar to the following:
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
* lowNumbers SymmetricExceptWith highNumbers...
* lowNumbers contains 7 elements: { 0 1 2 8 7 6 9 }
*/
//</snippet02>

private static void DisplaySet(HashSet<int> set)
{
Console.Write("{");
foreach (int i in set)
void DisplaySet(HashSet<int> set)
{
Console.Write(" {0}", i);
Console.Write("{");
foreach (int i in set)
{
Console.Write(" {0}", i);
}
Console.WriteLine(" }");
}
Console.WriteLine(" }");

/* This example provides output similar to the following:
* lowNumbers contains 6 elements: { 0 1 2 3 4 5 }
* highNumbers contains 7 elements: { 3 4 5 6 7 8 9 }
* lowNumbers SymmetricExceptWith highNumbers...
* lowNumbers contains 7 elements: { 0 1 2 8 7 6 9 }
*/
//</snippet02>
}
}
//</snippet01>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//<snippet01>
using System;
using System;
using System.Collections.Generic;

class Program
{
//<snippet02>
static void Main()
{
//<snippet01>
//<snippet03>
HashSet<int> evenNumbers = new HashSet<int>();
HashSet<int> oddNumbers = new HashSet<int>();
Expand Down Expand Up @@ -35,23 +34,22 @@ static void Main()
Console.Write("numbers contains {0} elements: ", numbers.Count);
DisplaySet(numbers);

}
//</snippet02>

private static void DisplaySet(HashSet<int> set)
{
Console.Write("{");
foreach (int i in set)
void DisplaySet(HashSet<int> set)
{
Console.Write(" {0}", i);
Console.Write("{");
foreach (int i in set)
{
Console.Write(" {0}", i);
}
Console.WriteLine(" }");
}
Console.WriteLine(" }");

/* This example produces output similar to the following:
* evenNumbers contains 5 elements: { 0 2 4 6 8 }
* oddNumbers contains 5 elements: { 1 3 5 7 9 }
* numbers UnionWith oddNumbers...
* numbers contains 10 elements: { 0 2 4 6 8 1 3 5 7 9 }
*/
//</snippet01>
}
}
/* This example produces output similar to the following:
* evenNumbers contains 5 elements: { 0 2 4 6 8 }
* oddNumbers contains 5 elements: { 1 3 5 7 9 }
* numbers UnionWith oddNumbers...
* numbers contains 10 elements: { 0 2 4 6 8 1 3 5 7 9 }
*/
//</snippet01>
Loading