Found 2628 Articles for Csharp

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

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

236 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

228 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

113 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

227 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

47 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

Get an ICollection containing the keys in HybridDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 08:09:38

54 Views

To get an ICollection containing the keys in HybridDictionary, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main(){       HybridDictionary dict = new HybridDictionary();       dict.Add("One", "Katie");       dict.Add("Two", "Andy");       dict.Add("Three", "Gary");       dict.Add("Four", "Mark");       dict.Add("Five", "Marie");       dict.Add("Six", "Sam");       dict.Add("Seven", "Harry");       dict.Add("Eight", "Kevin");       dict.Add("Nine", "Ryan");       String[] strArr = new String[dict.Count];       dict.Keys.CopyTo(strArr, 0);       for (int i ... Read More

Get an enumerator that iterates through the SortedDictionary in C#

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

84 Views

To get an enumerator that iterates through the SortedDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedDictionarysortedDict = new SortedDictionary();       sortedDict.Add(100, "Mobile");       sortedDict.Add(200, "Laptop");       sortedDict.Add(300, "Desktop");       sortedDict.Add(400, "Speakers");       sortedDict.Add(500, "Headphone");       sortedDict.Add(600, "Earphone");       Console.WriteLine("SortedDictionary key-value pairs...");       IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();       while (demoEnum.MoveNext())          Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + ... Read More

Get an enumerator that iterates through the ListDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 08:03:44

91 Views

To get an enumerator that iterates through the 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 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);       }       ListDictionary ... Read More

Get an ICollection containing the values in ListDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 08:00:18

99 Views

To get an ICollection containing the values 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 listDict = new ListDictionary();       listDict.Add("1", "Laptop");       listDict.Add("2", "Tablet");       listDict.Add("3", "Desktop");       listDict.Add("4", "Speaker");       listDict.Add("5", "Earphone");       listDict.Add("6", "Headphone");       ICollection col = listDict.Values;       foreach(String s in col){          Console.WriteLine(s);       }    } }OutputThis will produce the following output −Laptop ... Read More

Get an enumerator that iterates through the HybridDictionary in C#

AmitDiwan
Updated on 05-Dec-2019 07:57:29

61 Views

To get an enumerator that iterates through the 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", "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);       }       HybridDictionary ... Read More

Advertisements