Found 26504 Articles for Server Side Programming

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

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

137 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

119 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

156 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

159 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

125 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

311 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

311 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

178 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

How to get Second Element of the Tuple in C#?

AmitDiwan
Updated on 05-Dec-2019 10:07:08

312 Views

To get second element of the Tuple, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args) {       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 1st = "+tuple1.Item1);       Console.WriteLine("Tuple2 Item 1st = "+tuple2.Item1);       Console.WriteLine("Tuple1 Item 2nd ... Read More

C# Check if HybridDictionary is read only

AmitDiwan
Updated on 05-Dec-2019 09:58:15

91 Views

To check if HybridDictionary is read only, 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("Is ... Read More

Advertisements