Skip to content

Commit 9625432

Browse files
Create main.cs
1 parent 7c5dec1 commit 9625432

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Sorted_Set/main.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//Sorted Set elements must be unique
2+
//Sorted Set sorts elements in ascending order
3+
using System;
4+
using System.Collections.Generic;
5+
6+
class SortedSet{
7+
public static void Main()
8+
{
9+
//Instantiate a Sorted Set
10+
SortedSet<int> omars_Set = new SortedSet<int>();
11+
12+
//Pushing elements to
13+
omars_Set.Add(68);
14+
omars_Set.Add(98);
15+
omars_Set.Add(32);
16+
omars_Set.Add(1);
17+
omars_Set.Add(1174);
18+
Console.WriteLine("Elements of omars_Set:");
19+
20+
foreach(var elem in omars_Set)
21+
{
22+
Console.WriteLine(elem);
23+
}
24+
25+
//Creating a sorted setwith initial values
26+
SortedSet<int> omars_Set2 = new SortedSet<int>() {
27+
98,9,909,45};
28+
29+
Console.WriteLine("Elements of my_Set2:");
30+
foreach(var valu in omars_Set2)
31+
{
32+
Console.WriteLine(valu);
33+
}
34+
35+
//To remove an element from a set call the .Remove method with the value you want to remove
36+
omars_Set2.Remove(909);
37+
Console.WriteLine("Updated omars_Set2: ");
38+
39+
//Unexpected symbol `foreach' means you forgot a semi-colon
40+
foreach(var updSet2 in omars_Set2)
41+
{
42+
Console.WriteLine(updSet2);
43+
}
44+
45+
46+
//Checking whether an element exists
47+
if(omars_Set2.Contains(909) == true)
48+
{
49+
Console.WriteLine("Element Exists");
50+
}
51+
52+
else
53+
{
54+
Console.WriteLine("Element is not there");
55+
}
56+
//Empty out the set
57+
omars_Set2.Clear();
58+
59+
Console.WriteLine("The total number of elements within the set after performing the .Clear method:{0}", omars_Set2.Count);
60+
}
61+
}

0 commit comments

Comments
 (0)