Server Side Programming Articles - Page 2021 of 2646

Creating a synchronized wrapper for a SortedList object in C#

AmitDiwan
Updated on 10-Dec-2019 12:02:00

200 Views

To create a synchronized wrapper for a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       SortedList sortedList = new SortedList();       sortedList.Add("1", "Tom");       sortedList.Add("2", "Ryan");       sortedList.Add("3", "Nathan");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in sortedList){          Console.WriteLine("Key = "+d.Key + ", Value = " + d.Value);       }       SortedList sortedList2 = SortedList.Synchronized(sortedList);       Console.WriteLine("SortedList is synchronized? = "+sortedList2.IsSynchronized);    } }OutputThis will ... Read More

Count the number of key/value pairs in HybridDictionary in C#

AmitDiwan
Updated on 10-Dec-2019 11:58:43

132 Views

To count the number of key/value pairs in 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", "SUV");       dict1.Add("B", "MUV");       dict1.Add("C", "AUV");       Console.WriteLine("HybridDictionary1 elements...");       foreach(DictionaryEntry d in dict1){          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("Count of Key/value pairs in Dictionary1 = "+dict1.Count);       HybridDictionary dict2 = new HybridDictionary();     ... Read More

Copying the SortedList elements to an Array Object in C#

AmitDiwan
Updated on 10-Dec-2019 11:29:25

268 Views

To copy the SortedList elements to an Array 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("1", "AB");       list.Add("2", "CD");       list.Add("3", "EF");       list.Add("4", "GH");       list.Add("5", "IJ");       list.Add("6", "JK");       list.Add("7", "KL");       list.Add("8", "LM");       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in list){          Console.WriteLine("Key = "+d.Key + ", Value = ... Read More

Copying the HybridDictionary entries to an Array Instance in C#

AmitDiwan
Updated on 10-Dec-2019 11:26:47

152 Views

To copy the HybridDictionary entries to an Array Instance, 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();       dict.Add("1", "SUV");       dict.Add("2", "AUV");       dict.Add("3", "Utility Vehicle");       dict.Add("4", "MUV");       dict.Add("5", "Compact Car");       dict.Add("6", "Convertible");       Console.WriteLine("HybridDictionary Key and Value pairs...");       foreach(DictionaryEntry entry in dict){          Console.WriteLine("{0} and {1} ", entry.Key, entry.Value);       }   ... Read More

Copying the Hashtable elements to an Array Instance in C#

AmitDiwan
Updated on 10-Dec-2019 11:23:32

245 Views

To copy the Hashtable elements to an Array Instance, the code is as follows−Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       Hashtable hash = new Hashtable();       hash.Add("1", "AB");       hash.Add("2", "CD");       hash.Add("3", "EF");       hash.Add("4", "GH");       hash.Add("5", "IJ");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry entry in hash){          Console.WriteLine("{0} and {1} ", entry.Key, entry.Value);       }       Console.WriteLine("Copied to Array Instance...");       DictionaryEntry[] ... Read More

How to get a subset in a SortedSet in C#?

AmitDiwan
Updated on 10-Dec-2019 11:21:06

173 Views

To get a subset in a 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);       }       SortedSet set2 = new SortedSet();       set2.Add("BC");       set2.Add("CD");       set2.Add("DE");       set2.Add("EF");       ... Read More

How to create a Stack in C#?

AmitDiwan
Updated on 10-Dec-2019 11:17:37

144 Views

To create a 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(100);       stack.Push(150);       stack.Push(175);       stack.Push(200);       stack.Push(225);       stack.Push(250);       stack.Push(300);       stack.Push(400);       stack.Push(450);       stack.Push(500);       Console.WriteLine("Elements in the Stack:");       foreach(var val in stack){          Console.WriteLine(val);       }       Console.WriteLine("Count of elements ... Read More

Copying the entire ArrayList to 1-D Array starting at the specified index in C#

AmitDiwan
Updated on 10-Dec-2019 11:14:33

109 Views

To copy the entire ArrayList to a 1-D array starting at the specified index, 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("PQ");       list.Add("RS");       list.Add("TU");       list.Add("UV");       list.Add("WX");       list.Add("YZ");       Console.WriteLine("ArrayList elements...");       for (int i = 0; i < list.Count; i++) {          Console.WriteLine(list[i]);       }       String[] strArr = new String[6] ... Read More

Copying the elements of ArrayList to a new array in C#

AmitDiwan
Updated on 10-Dec-2019 11:08:53

168 Views

To copy the elements of ArrayList to a new array, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       ArrayList list = new ArrayList(10);       list.Add("A");       list.Add("B");       list.Add("C");       list.Add("D");       list.Add("E");       list.Add("F");       list.Add("G");       list.Add("H");       list.Add("I");       list.Add("J");       Console.WriteLine("ArrayList elements...");       foreach(string str in list){          Console.WriteLine(str);       }     ... Read More

How to create a SortedList in C#?

AmitDiwan
Updated on 10-Dec-2019 11:06:04

147 Views

To create a 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){          Console.WriteLine("Key = ... Read More

Advertisements