Found 2587 Articles for Csharp

Check if an element is in the Queue in C#

AmitDiwan
Updated on 04-Dec-2019 06:43:34

202 Views

To check if an element is in the Queue, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       Queue queue = new Queue();       queue.Enqueue("Electronics");       queue.Enqueue("Accessories");       queue.Enqueue("Toys");       queue.Enqueue("Books");       queue.Enqueue("Furniture");       queue.Enqueue("Clothing");       queue.Enqueue("Footwear");       queue.Enqueue("Cookware");       queue.Enqueue("Pet Supplies");       Console.WriteLine("Elements in the Queue...");       foreach(var element in queue){          Console.WriteLine(element);       }       Console.WriteLine("Do ... Read More

Check if an element is in the Collection in C#

AmitDiwan
Updated on 04-Dec-2019 06:39:03

221 Views

To check if an element is in the Collection, the code is as follows −Example Live Demousing System; using System.Collections.ObjectModel; public class Demo {    public static void Main(){       Collection col = new Collection();       col.Add(10);       col.Add(20);       col.Add(30);       col.Add(40);       col.Add(50);       col.Add(60);       col.Add(70);       col.Add(80);       Console.WriteLine("Elements in the Collection...");       foreach(int val in col){          Console.WriteLine(val);       }       Console.WriteLine("Does the collection has the element ... Read More

Check if an array object is equal to another array object in C#

AmitDiwan
Updated on 04-Dec-2019 06:35:35

283 Views

To check if an array object is equal to another array object, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       String[] strArr1 = new String[3] { "John", "Jacob", "Tim"};       String[] strArr2 = new String[3] { "Tom", "Brad", "Bradley"};       Console.WriteLine("First String array...");       foreach(string val in strArr1){          Console.WriteLine(val);       }       Console.WriteLine("Second String array...");       foreach(string val in strArr2){          Console.WriteLine(val);       }       ... Read More

Check if a HashSet is a proper subset of the specified collection in C#

AmitDiwan
Updated on 04-Dec-2019 06:31:17

143 Views

To check if a HashSet is a proper subset of the specified collection, try the following code −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       HashSet set1 = new HashSet();       set1.Add(70);       set1.Add(100);       set1.Add(125);       set1.Add(150);       Console.WriteLine("Elements in HashSet1");       foreach(int val in set1){          Console.WriteLine(val);       }       HashSet set2 = new HashSet();       set2.Add(30);       set2.Add(60);       set2.Add(70);       ... Read More

Check if a HashSet contains the specified element in C#

AmitDiwan
Updated on 04-Dec-2019 06:20:37

746 Views

To check if a HashSet contains the specified element, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       HashSet set1 = new HashSet();       set1.Add(25);       set1.Add(50);       set1.Add(75);       set1.Add(100);       set1.Add(125);       set1.Add(150);       Console.WriteLine("Elements in HashSet1");       foreach(int val in set1){          Console.WriteLine(val);       }       HashSet set2 = new HashSet();       set2.Add(30);       set2.Add(60);     ... Read More

Check if an array is read-only or not in C#

AmitDiwan
Updated on 04-Dec-2019 06:17:11

217 Views

To check if an array is read-only or not, try the below code −Example Live Demousing System; public class Demo {    public static void Main(){       string[] products = new string[] { };       Console.WriteLine("One or more planets begin with 'E'? = {0}",          Array.Exists(products, ele => ele.StartsWith("E")));       Console.WriteLine("Is the array having fixed size? = " + products.IsFixedSize);       Console.WriteLine("Is the array read only? = " + products.IsReadOnly);    } }OutputThis will produce the following code −One or more planets begin with 'E'? = False Is the array ... Read More

Get an enumerator that iterates through the Dictionary in C#

AmitDiwan
Updated on 04-Dec-2019 06:06:52

531 Views

To get an enumerator that iterates through the Dictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict = new Dictionary();       dict.Add(100, "Laptop");       dict.Add(150, "Desktop");       dict.Add(200, "Earphone");       dict.Add(300, "Tablet");       dict.Add(500, "Speakers");       dict.Add(750, "HardDisk");       dict.Add(1000, "SSD");       IDictionaryEnumerator demoEnum = dict.GetEnumerator();       Console.WriteLine("Enumerator iterating key-value pairs...");       while (demoEnum.MoveNext())       Console.WriteLine("Key = " + demoEnum.Key ... Read More

Get an enumerator that iterates through StringCollection in C#

AmitDiwan
Updated on 04-Dec-2019 06:02:56

156 Views

To get an enumerator that iterates through StringCollection, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringCollection stringCol = new StringCollection();       String[] arr = new String[] { "100", "200", "300", "400", "500" };       Console.WriteLine("Array elements...");       foreach (string res in arr){          Console.WriteLine(res);       }       stringCol.AddRange(arr);       Console.WriteLine("Does the specified string is in the StringCollection? = "+stringCol.Contains("800"));       Console.WriteLine("Total number of elements = "+stringCol.Count);     ... Read More

Removing all nodes from LinkedList in C#

AmitDiwan
Updated on 04-Dec-2019 05:58:13

203 Views

To remove all nodes from LinkedList, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       int [] num = {10, 20, 30, 40, 50};       LinkedList list = new LinkedList(num);       Console.WriteLine("LinkedList nodes...");       foreach (var n in list) {          Console.WriteLine(n);       }       list.Clear();       Console.WriteLine("LinkedList is empty now!");       foreach (var n in list) {          Console.WriteLine(n);       }    } ... Read More

Removing all entries from the StringDictionary in C#

AmitDiwan
Updated on 04-Dec-2019 05:52:40

100 Views

To remove all entries from the StringDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringDictionary strDict1 = new StringDictionary();       strDict1.Add("A", "John");       strDict1.Add("B", "Andy");       strDict1.Add("C", "Tim");       strDict1.Add("D", "Ryan");       strDict1.Add("E", "Kevin");       strDict1.Add("F", "Katie");       strDict1.Add("G", "Brad");       Console.WriteLine("StringDictionary1 elements...");       foreach(DictionaryEntry d in strDict1){          Console.WriteLine(d.Key + " " + d.Value);       }       ... Read More

Advertisements