Programming Articles - Page 2268 of 3366

Remove entry with specified key from the StringDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 11:14:01

123 Views

To remove entry with specified key 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 key-value pairs...");       foreach(DictionaryEntry de in strDict1) {          Console.WriteLine(de.Key + " " + de.Value);     ... Read More

Remove entry with specified key from OrderedDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 11:10:13

170 Views

To remove entry with specified key from OrdererdDictionary in C#, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       OrderedDictionary dict = new OrderedDictionary();       dict.Add("A", "Books");       dict.Add("B", "Electronics");       dict.Add("C", "Smart Wearables");       dict.Add("D", "Pet Supplies");       dict.Add("E", "Clothing");       dict.Add("F", "Footwear");       Console.WriteLine("OrderedDictionary elements...");       foreach(DictionaryEntry d in dict) {          Console.WriteLine(d.Key + " " + d.Value);       }   ... Read More

Get the object at the beginning of the Queue – Peek Operation in C#

AmitDiwan
Updated on 05-Dec-2019 11:04:35

142 Views

To get the object at the beginning of 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("A");       queue.Enqueue("B");       queue.Enqueue("C");       queue.Enqueue("D");       queue.Enqueue("E");       queue.Enqueue("F");       queue.Enqueue("G");       Console.WriteLine("Count of elements = "+queue.Count);       Console.WriteLine("Element at the beginning of queue = " + queue.Peek());    } }OutputThis will produce the following output −Count of elements = 7 Element at the beginning of queue = AExampleLet us see another ... Read More

Get or set the value associated with specified key in SortedList in C#

AmitDiwan
Updated on 05-Dec-2019 10:57:14

123 Views

To get or set the value associated with specified key in SortedList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       SortedList list = new SortedList ();       list.Add("A", "Books");       list.Add("B", "Electronics");       list.Add("C", "Appliances");       list.Add("D", "Pet Supplies");       list.Add("E", "Clothing");       list.Add("F", "Footwear");       Console.WriteLine("Value associated with key E = "+list["E"]);       list["E"] = "HDD";       Console.WriteLine("Value associated with key E [Updated] = "+list["E"]);   ... Read More

Check if two StringDictionary objects are equal or not in C#

AmitDiwan
Updated on 05-Dec-2019 10:53:23

166 Views

To check if two StringDictionary objects are equal or not, the code is as follows −Example Live Demousing System; 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");       StringDictionary strDict2 = new StringDictionary();       strDict2.Add("A", "John");       strDict2.Add("B", "Andy");       strDict2.Add("C", "Tim");       strDict2.Add("D", ... Read More

Check if two StringCollection objects are equal in C#

AmitDiwan
Updated on 05-Dec-2019 10:48:15

165 Views

To check if two StringCollection objects are equal, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection strCol1 = new StringCollection();       strCol1.Add("Accessories");       strCol1.Add("Books");       strCol1.Add("Electronics");       Console.WriteLine("StringCollection1 elements...");       foreach (string res in strCol1) {          Console.WriteLine(res);       }       StringCollection strCol2 = new StringCollection();       strCol2.Add("Accessories");       strCol2.Add("Books");       strCol2.Add("Electronics");       Console.WriteLine("StringCollection2 elements...");       foreach ... Read More

Get or set the value associated with specified key in ListDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 10:42:04

132 Views

To get or set the value associated with specified key 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 dict = new ListDictionary();       dict.Add("A", "Books");       dict.Add("B", "Electronics");       dict.Add("C", "Appliances");       dict.Add("D", "Pet Supplies");       dict.Add("E", "Clothing");       dict.Add("F", "Footwear");       Console.WriteLine("Value associated with key C = "+dict["C"]);    } }OutputThis will produce the following output −Value associated with key C = AppliancesExampleLet us see another example − Live Demousing System; using ... Read More

Remove elements from a SortedSet that match the predicate in C#

AmitDiwan
Updated on 05-Dec-2019 10:38:23

321 Views

To remove elements from a SortedSet that match the predicate, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i) {       return ((i % 10) == 0);    }    public static void Main(String[] args) {       SortedSet set1 = new SortedSet();       set1.Add(200);       set1.Add(215);       set1.Add(310);       set1.Add(500);       set1.Add(600);       Console.WriteLine("SortedSet elements...");       foreach (int i in set1) {          Console.WriteLine(i);       } ... Read More

Remove elements from a HashSet with conditions defined by the predicate in C#

AmitDiwan
Updated on 05-Dec-2019 10:34:20

315 Views

To remove elements from a HashSet with conditions defined by the predicate, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i) {       return (i == 100);    }    public static void Main(String[] args) {       HashSet list = new HashSet();       list.Add(100);       list.Add(300);       list.Add(400);       list.Add(500);       list.Add(600);       Console.WriteLine("HashSet elements...");       foreach (int i in list) {          Console.WriteLine(i);       } ... Read More

Remove element at specified index of Collection in C#

AmitDiwan
Updated on 05-Dec-2019 10:26:35

183 Views

To remove element at specified index of 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("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 More

Advertisements