Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Csharp Articles
Page 27 of 196
Remove the specified element from a HashSet in C#
To remove the specified element from a HashSet, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(){ HashSet set1 = new HashSet(); set1.Add("AB"); set1.Add("CD"); set1.Add("EF"); set1.Add("AB"); set1.Add("IJ"); set1.Add("KL"); set1.Add("EF"); set1.Add("OP"); Console.WriteLine("Elements in HashSet1"); foreach(string val in set1){ Console.WriteLine(val); } HashSet set2 = new HashSet(); set2.Add("EF"); ...
Read MoreGet an enumerator that iterates through Collection in C#
To get an enumerator that iterates through Collection, the code is as follows −Exampleusing System; using System.Collections.ObjectModel; public class Demo { public static void Main(){ Collection col = new Collection(); col.Add("Andy"); col.Add("Kevin"); col.Add("John"); col.Add("Kevin"); col.Add("Mary"); col.Add("Katie"); col.Add("Barry"); col.Add("Nathan"); col.Add("Mark"); Console.WriteLine("Count of elements = "+ col.Count); Console.WriteLine("Iterating through the collection..."); var enumerator = col.GetEnumerator(); while (enumerator.MoveNext()) { ...
Read MoreRemove a range of elements from the List in C#
To remove a range of elements from the List, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(String[] args){ List list1 = new List(); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four"); list1.Add("Five"); Console.WriteLine("Elements in List1..."); foreach (string res in list1){ Console.WriteLine(res); } List list2 = new List(); list2.Add("India"); list2.Add("US"); list2.Add("UK"); ...
Read MoreConvert Queue To array in C#
To convert queue to the array, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(){ Queue queue = new Queue(); queue.Enqueue(100); queue.Enqueue(200); queue.Enqueue(300); queue.Enqueue(400); queue.Enqueue(500); queue.Enqueue(600); queue.Enqueue(700); queue.Enqueue(800); queue.Enqueue(900); queue.Enqueue(1000); Console.WriteLine("Queue..."); foreach(int i in queue){ Console.WriteLine(i); } int[] intArr = queue.ToArray(); ...
Read MoreRemoving first occurrence of object from Collection in C#
To remove the first occurrence of the object from Collection, the code is as follows −Exampleusing System; using System.Collections.ObjectModel; public class Demo { public static void Main(){ Collection col = new Collection(); col.Add("Andy"); col.Add("Kevin"); col.Add("John"); col.Add("Nathan"); col.Add("Nathan"); col.Add("Katie"); col.Add("Barry"); col.Add("Nathan"); col.Add("Mark"); Console.WriteLine("Count of elements = "+ col.Count); Console.WriteLine("Iterating through the collection..."); var enumerator = col.GetEnumerator(); while (enumerator.MoveNext()) ...
Read MoreConvert Stack to array in C#
To convert stack to the array, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(){ Stack stack = new Stack(); stack.Push("AB"); stack.Push("CD"); stack.Push("FG"); stack.Push("KL"); Console.WriteLine("Array..."); foreach(string i in stack){ Console.WriteLine(i); } string[] strArr = stack.ToArray(); Console.WriteLine("Convert Stack to Array..."); foreach(string i in strArr){ Console.WriteLine(i); } } ...
Read MoreRemoving first occurrence of specified value from LinkedList in C#
To remove the first occurrence of specified value from LinkedList, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList list = new LinkedList(); list.AddLast("A"); list.AddLast("B"); list.AddLast("C"); list.AddLast("A"); list.AddLast("E"); list.AddLast("F"); list.AddLast("A"); list.AddLast("H"); list.AddLast("A"); list.AddLast("j"); Console.WriteLine("Count of nodes = " + list.Count); Console.WriteLine("Elements in LinkedList... (Enumerator iterating through LinkedList)"); LinkedList.Enumerator ...
Read MoreGet the number of elements contained in the Stack in C#
To get the number of elements contained in the Stack, the code is as follows −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main(){ Stack stack = new Stack(); stack.Push("A"); stack.Push("B"); stack.Push("C"); stack.Push("D"); stack.Push("E"); stack.Push("F"); stack.Push("G"); stack.Push("H"); Console.WriteLine("Count of elements = "+stack.Count); Console.WriteLine("Elements in Stack..."); foreach (string res in stack){ Console.WriteLine(res); } ...
Read MoreGet the number of key/value pairs contained in ListDictionary in C#
To get the number of key/value pairs contained in ListDictionary, the code is as follows−Exampleusing System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ ListDictionary dict1 = new ListDictionary(); dict1.Add("A", "Books"); dict1.Add("B", "Electronics"); dict1.Add("C", "Smart Wearables"); dict1.Add("D", "Pet Supplies"); dict1.Add("E", "Clothing"); dict1.Add("F", "Footwear"); Console.WriteLine("ListDictionary1 elements..."); foreach(DictionaryEntry d in dict1){ Console.WriteLine(d.Key + " " + d.Value); } ListDictionary dict2 ...
Read MoreGet the number of key/value pairs in the StringDictionary in C#
To get the number of key/value pairs in the StringDictionary, the code is as follows −Exampleusing System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ StringDictionary strDict = new StringDictionary(); strDict.Add("1", "One"); strDict.Add("2", "Two"); strDict.Add("3", "Three"); strDict.Add("4", "Four"); Console.WriteLine("StringDictionary key-value pairs..."); IEnumerator demoEnum = strDict.GetEnumerator(); DictionaryEntry d; while (demoEnum.MoveNext()) { d = (DictionaryEntry)demoEnum.Current; Console.WriteLine("Key = " + d.Key + ", ...
Read More