Found 2628 Articles for Csharp

Get the number of key/value pairs contained in ListDictionary in C#

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

76 Views

To get the number of key/value pairs contained 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 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 ... Read More

Removing first occurrence of specified value from LinkedList in C#

AmitDiwan
Updated on 06-Dec-2019 05:37:47

179 Views

To remove the first occurrence of specified value from 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("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)");       ... Read More

Removing first occurrence of object from Collection in C#

AmitDiwan
Updated on 06-Dec-2019 05:32:14

70 Views

To remove the first occurrence of the object from 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("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 ... Read More

Remove a range of elements from the List in C#

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

363 Views

To remove a range of elements from the List, the code is as follows −Example Live Demousing 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 More

Remove the specified element from a HashSet in C#

AmitDiwan
Updated on 06-Dec-2019 05:23:44

293 Views

To remove the specified element from a HashSet, 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("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();       ... Read More

Add key and value into OrderedDictionary collection in C#

AmitDiwan
Updated on 05-Dec-2019 13:24:33

112 Views

To add key and value into OrderedDictionary collection, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       OrderedDictionary dict1 = new OrderedDictionary();       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("OrderedDictionary1 elements...");       foreach(DictionaryEntry d in dict1) {          Console.WriteLine(d.Key + " " + d.Value);       }       ... Read More

Add element to SortedSet in C#

AmitDiwan
Updated on 05-Dec-2019 13:20:35

106 Views

To add element to 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(100);       set1.Add(200);       set1.Add(300);       set1.Add(400);       Console.WriteLine("Elements in SortedSet...");       foreach (int res in set1) {          Console.WriteLine(res);       }       Console.WriteLine("Does the SortedSet contains the element 500? = "+set1.Contains(500));    } }OutputThis will produce the following output −Elements in SortedSet... 100 200 300 400 Does the SortedSet contains the element 500? = FalseExampleLet us ... Read More

Getting the key at the specified index of a SortedList object in C#

AmitDiwan
Updated on 05-Dec-2019 13:18:55

65 Views

To get the key at the specified index of a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list1 = new SortedList();       list1.Add("One", 1);       list1.Add("Two ", 2);       list1.Add("Three ", 3);       list1.Add("Four", 4);       list1.Add("Five", 5);       list1.Add("Six", 6);       list1.Add("Seven ", 7);       list1.Add("Eight ", 8);       list1.Add("Nine", 9);       list1.Add("Ten", 10);       Console.WriteLine("SortedList1 elements..."); ... Read More

Getting the index of the specified key in a SortedList object in C#

AmitDiwan
Updated on 05-Dec-2019 13:13:21

200 Views

To get index of the specified key in a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list = new SortedList();       list.Add("One", "Finance");       list.Add("Two", "Marketing");       list.Add("Three", "Sales");       list.Add("Four", "Purchase");       list.Add("Five", "Operations");       list.Add("Six", "IT");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in list) {          Console.WriteLine(d.Key + " " + d.Value);       }       ... Read More

Getting index of the specified value in a SortedList object in C#

AmitDiwan
Updated on 05-Dec-2019 13:09:37

51 Views

To get index of the specified value in a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list1 = new SortedList();       list1.Add("One", 1);       list1.Add("Two ", 2);       list1.Add("Three ", 3);       list1.Add("Four", 4);       list1.Add("Five", 5);       list1.Add("Six", 6);       list1.Add("Seven ", 7);       list1.Add("Eight ", 8);       list1.Add("Nine", 9);       list1.Add("Ten", 10);       Console.WriteLine("SortedList1 elements...");   ... Read More

Advertisements