Found 26504 Articles for Server Side Programming

Get a read-only copy of the OrderedDictionary in C#

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

170 Views

To get a read-only copy of the OrderedDictionary, 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);       }       OrderedDictionary dict2 ... Read More

Check if two Tuple Objects are equal in C#

AmitDiwan
Updated on 05-Dec-2019 06:55:15

156 Views

To check if two Tuple objects are equal, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(150, 400, 500, 700, 100, 1200, 1500);       var tuple2 = Tuple.Create(150, 400, 500, 700, 100, 1200, 1500);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));    } }OutputThis will produce the following output −Is Tuple1 equal to Tuple2? = TrueExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main(String[] args){       var tuple1 = ... Read More

Check if two StringBuilder objects are Equal in C#

AmitDiwan
Updated on 05-Dec-2019 06:51:17

148 Views

To check if two StringBuilder objects are equal, the code is as follows −Example Live Demousing System; using System.Text; public class Demo {    public static void Main(String[] args){       StringBuilder strBuilder1 = new StringBuilder("Tim");       StringBuilder strBuilder2 = new StringBuilder("Tom");       StringBuilder strBuilder3 = new StringBuilder();       strBuilder2 = strBuilder3;       Console.WriteLine("Is StringBuilder3 equal to StringBuilder2? = "+strBuilder3.Equals(strBuilder2));    } }OutputThis will produce the following output −Is StringBuilder3 equal to StringBuilder2? = TrueExampleLet us see another example − Live Demousing System; using System.Text; public class Demo {    public static void ... Read More

Check if two String objects have the same value in C#

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

169 Views

To check if two String objects have the same value, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       string str1 = "John";       string str2 = "John";       Console.WriteLine("String 1 = "+str1);       Console.WriteLine("String 2 = "+str2);       Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2));    } }OutputThis will produce the following output −String 1 = John String 2 = John String 1 is equal to String 2: TrueExampleLet us see another example − Live Demousing System; public ... Read More

Creating a read-only wrapper for the ArrayList in C#

AmitDiwan
Updated on 05-Dec-2019 06:38:28

185 Views

To create a read-only wrapper for ArrayList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       ArrayList list = new ArrayList();       list.Add("One");       list.Add("Two");       list.Add("Three");       list.Add("Four");       list.Add("Five");       list.Add("Six");       list.Add("Seven");       list.Add("Eight");       Console.WriteLine("ArrayList elements...");       foreach(string str in list){          Console.WriteLine(str);       }       Console.WriteLine("ArrayList is read-only? = "+list.IsReadOnly);    } }OutputThis will produce ... Read More

Get an enumerator that iterates through the SortedList in C#

AmitDiwan
Updated on 05-Dec-2019 06:34:48

444 Views

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

Creating a HybridDictionary with specified initial size in C#

AmitDiwan
Updated on 05-Dec-2019 06:29:24

96 Views

To create a HybridDictionary with specified initial size, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary dict = new HybridDictionary(5);       dict.Add("A", "AB");       dict.Add("B", "BC");       dict.Add("C", "DE");       dict.Add("D", "FG");       dict.Add("E", "HI");       Console.WriteLine("Key/Value pairs...");       foreach(DictionaryEntry d in dict)       Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);    } }OutputThis will produce the following output −Key/Value pairs... Key = A, ... Read More

Creating a Case-Sensitive HybridDictionary with specified initial size in C#

AmitDiwan
Updated on 05-Dec-2019 06:25:29

113 Views

To create a case-sensitive HybridDictionary with specified initial size, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary myDict = new HybridDictionary(5, false);       myDict.Add("A", "AB");       myDict.Add("B", "BC");       myDict.Add("C", "DE");       myDict.Add("D", "FG");       myDict.Add("e", "fg");       Console.WriteLine("Key/Value pairs...");       foreach(DictionaryEntry de in myDict)       Console.WriteLine("Key = "+de.Key + ", Value = " + de.Value);    } }OutputThis will produce the following output −Key/Value pairs... Key ... Read More

Create HashSet from another collection in C#

AmitDiwan
Updated on 05-Dec-2019 06:22:40

168 Views

To create HashSet from another Collection, 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(100);       set1.Add(200);       set1.Add(300);       Console.WriteLine("HashSet created from another collection...");       foreach(int i in set1){          Console.WriteLine(i);       }       HashSet set2 = new HashSet(set1);       Console.WriteLine("HashSet created from another collection...");       foreach(int i in set2){          Console.WriteLine(i);       } ... Read More

Create a Stack from a collection in C#

AmitDiwan
Updated on 05-Dec-2019 06:18:09

126 Views

To create a Stack from a collection, 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(100);       stack.Push(200);       stack.Push(300);       stack.Push(400);       stack.Push(500);       stack.Push(600);       stack.Push(700);       stack.Push(800);       stack.Push(900);       stack.Push(1000);       Console.WriteLine("Stack elements...");       foreach(int val in stack){          Console.WriteLine(val);       }       Console.WriteLine("Array elements..."); ... Read More

Advertisements