Found 2628 Articles for Csharp

Get the minimum value in the SortedSet in C#

AmitDiwan
Updated on 06-Dec-2019 06:21:36

78 Views

To get the minimum value in the SortedSet, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedSet set1 = new SortedSet();       set1.Add("AB");       set1.Add("BC");       set1.Add("CD");       set1.Add("EF");       Console.WriteLine("Elements in SortedSet1...");       foreach (string res in set1){          Console.WriteLine(res);       }       Console.WriteLine("Maximum element in SortedSet1 = " + set1.Max);       Console.WriteLine("Minimum element in SortedSet1 = " + set1.Min);       SortedSet ... Read More

Get an enumerator that iterates through the Hashtable in C#

AmitDiwan
Updated on 06-Dec-2019 06:18:12

265 Views

To get an enumerator that iterates through the Hashtable, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       Hashtable hash = new Hashtable(10);       hash.Add("1", "A");       hash.Add("2", "B");       hash.Add("3", "C");       hash.Add("4", "D");       hash.Add("5", "E");       hash.Add("6", "F");       hash.Add("7", "G");       hash.Add("8", "H");       hash.Add("9", "I");       hash.Add("10", "J");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry entry in ... Read More

Removing all entries from HybridDictionary in C#

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

59 Views

To remove all entries from HybridDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary dict1 = new HybridDictionary();       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("HybridDictionary1 elements...");       foreach(DictionaryEntry d in dict1){          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("Count of Key/value pairs ... Read More

Remove all objects from the Stack in C#

AmitDiwan
Updated on 06-Dec-2019 06:10:26

113 Views

To remove all objects from the Stack, the code is as follows −Example Live Demousing 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 More

Get the maximum value in the SortedSet in C#

AmitDiwan
Updated on 06-Dec-2019 06:07:33

85 Views

To get the maximum value in the SortedSet, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedSet set1 = new SortedSet();       set1.Add("AB");       set1.Add("BC");       set1.Add("CD");       set1.Add("EF");       Console.WriteLine("Elements in SortedSet1...");       foreach (string res in set1){          Console.WriteLine(res);       }       Console.WriteLine("Maximum element in SortedSet1 = " + set1.Max);       SortedSet set2 = new SortedSet();       set2.Add("BC");       ... Read More

Get the last node of the LinkedList in C#

AmitDiwan
Updated on 06-Dec-2019 06:03:45

233 Views

To get the last node of the LinkedList, the code is as follows −Example Live Demousing 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("D");       list.AddLast("E");       list.AddLast("F");       list.AddLast("G");       list.AddLast("H");       list.AddLast("I");       list.AddLast("J");       Console.WriteLine("Count of nodes = " + list.Count);       Console.WriteLine("First Node = "+list.First.Value);       Console.WriteLine("Last Node = "+list.Last.Value);   ... Read More

Get an ICollection containing the values in HybridDictionary in C#

AmitDiwan
Updated on 06-Dec-2019 05:59:45

81 Views

To get an ICollection containing the values in HybridDictionary, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary dict = new HybridDictionary();       dict.Add("One", "Katie");       dict.Add("Two", "Andy");       dict.Add("Three", "Gary");       dict.Add("Four", "Mark");       dict.Add("Five", "Marie");       dict.Add("Six", "Sam");       dict.Add("Seven", "Harry");       dict.Add("Eight", "Kevin");       dict.Add("Nine", "Ryan");       String[] strArr = new String[dict.Count];       dict.Values.CopyTo(strArr, 0);       for (int i ... Read More

Get an ICollection containing the keys in ListDictionary in C#

AmitDiwan
Updated on 06-Dec-2019 05:53:13

75 Views

To get an ICollection containing the keys in ListDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       ListDictionary listDict = new ListDictionary();       listDict.Add("1", "Laptop");       listDict.Add("2", "Tablet");       listDict.Add("3", "Desktop");       listDict.Add("4", "Speaker");       listDict.Add("5", "Earphone");       listDict.Add("6", "Headphone");       ICollection col = listDict.Keys;       foreach(String s in col){          Console.WriteLine(s);       }    } }OutputThis will produce the following output −1 ... Read More

Removing the node at the start of the LinkedList in C#

AmitDiwan
Updated on 02-May-2020 08:18:24

63 Views

To remove the node at the start of the LinkedList, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       LinkedList list = new LinkedList();       list.AddLast("One");       list.AddLast("Two");       list.AddLast("Three");       list.AddLast("Three");       list.AddLast("Three");       list.AddLast("Four");       Console.WriteLine("Count of nodes = " + list.Count);       Console.WriteLine("Elements in LinkedList... (Enumerator iterating through LinkedList)");       LinkedList.Enumerator demoEnum = list.GetEnumerator();       while (demoEnum.MoveNext()) {          string res ... Read More

Get the number of key/value pairs in the StringDictionary in C#

AmitDiwan
Updated on 06-Dec-2019 05:46:05

55 Views

To get the number of key/value pairs in 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 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

Advertisements