Found 2628 Articles for Csharp

Remove all elements from OrderedDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 07:19:04

61 Views

To remove all elements from 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 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);       }       Console.WriteLine("Count of elements in ... Read More

Check if ListDictionary is synchronized in C#

AmitDiwan
Updated on 05-Dec-2019 07:16:33

60 Views

To check if ListDictionary is synchronized, 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("1", "SUV");       dict.Add("2", "Sedan");       dict.Add("3", "Utility Vehicle");       dict.Add("4", "Compact Car");       dict.Add("5", "SUV");       dict.Add("6", "Sedan");       dict.Add("7", "Utility Vehicle");       dict.Add("8", "Compact Car");       dict.Add("9", "Crossover");       dict.Add("10", "Electric Car");       Console.WriteLine("ListDictionary elements...");       foreach(DictionaryEntry d ... Read More

Check if ListDictionary is read-only in C#

AmitDiwan
Updated on 05-Dec-2019 07:12:55

71 Views

To check if ListDictionary 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(){       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);       }       Console.WriteLine("Is the ListDictionary1 having ... Read More

Remove all elements from a SortedList in C#

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

77 Views

To remove all elements from 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){       ... Read More

Remove all elements from a HashSet in C#

AmitDiwan
Updated on 05-Dec-2019 07:04:01

122 Views

To remove all elements from a HashSet, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args){       HashSet set1 = new HashSet();       set1.Add("A");       set1.Add("B");       set1.Add("C");       set1.Add("D");       set1.Add("E");       set1.Add("F");       set1.Add("G");       set1.Add("H");       Console.WriteLine("Elements in HashSet1...");       foreach (string res in set1){          Console.WriteLine(res);       }       HashSet set2 = new HashSet();     ... Read More

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

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

101 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

107 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

95 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

142 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

131 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

Advertisements