Found 2628 Articles for Csharp

Check if ListDictionary contains a specific key in C#

AmitDiwan
Updated on 06-Dec-2019 10:44:55

58 Views

To check if ListDictionary contains a specific key, 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);       }     ... Read More

Getting an enumerator that iterates through HashSet in C#

AmitDiwan
Updated on 06-Dec-2019 10:39:43

280 Views

To get an enumerator that iterates through 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 ... Read More

How to get the HashCode for the string in C#?

AmitDiwan
Updated on 06-Dec-2019 10:34:45

179 Views

To get the HashCode for the string, the code is as follows, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args) {       string str1 = "Akon";       string str2 = "Eminem";       Console.WriteLine("String 1 = "+str1);       Console.WriteLine("HashCode of String 1 = "+str1.GetHashCode());       Console.WriteLine("String 2 = "+str2);       Console.WriteLine("HashCode of String 2 = "+str2.GetHashCode());       Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2));    } }OutputThis will produce the following output −String 1 = Akon HashCode of String 1 = 416613838 String 2 = Eminem ... Read More

Get the number of nodes contained in LinkedList in C#

AmitDiwan
Updated on 06-Dec-2019 10:26:03

179 Views

To get the number of nodes contained in the LinkedList, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       LinkedList list = new LinkedList();       list.AddLast("A");       list.AddLast("B");       list.AddLast("C");       list.AddLast("D");       list.AddLast("E");       list.AddLast("F");       list.AddLast("G");       list.AddLast("H");       list.AddLast("I");       list.AddLast("J");       Console.WriteLine("Count of nodes = " + list.Count);       Console.WriteLine("First Node = "+list.First.Value);       list.Clear();   ... Read More

Check if HybridDictionary has fixed size in C#

AmitDiwan
Updated on 06-Dec-2019 10:22:24

58 Views

To check if HybridDictionary has fixed 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 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

Adding new node or value at the end of LinkedList in C#

AmitDiwan
Updated on 06-Dec-2019 10:18:15

114 Views

To add new node or value at the end of LinkedList, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       LinkedList list = new LinkedList();       list.AddLast("A");       list.AddLast("B");       list.AddLast("C");       list.AddLast("D");       list.AddLast("E");       list.AddLast("F");       Console.WriteLine("Count of nodes = " + list.Count);       Console.WriteLine("Elements in LinkedList...");       foreach (string res in list) {          Console.WriteLine(res);       }       ... Read More

Adding elements to the end of the ArrayList in C#

AmitDiwan
Updated on 06-Dec-2019 10:15:10

152 Views

To add elements to the end of the ArrayList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list = new ArrayList();       list.Add("Andy");       list.Add("Gary");       list.Add("Katie");       list.Add("Amy");       Console.WriteLine("Elements in ArrayList...");       foreach (string res in list) {          Console.WriteLine(res);       }       string[] strArr = { "John", "Jacob" };       list.AddRange(strArr);       Console.WriteLine("Elements in ArrayList...UPDATED");     ... Read More

Adding an element to the List in C#

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

193 Views

To add an element to the List, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list = new List();       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("Enumerator iterates through the list elements...");       List.Enumerator demoEnum = list.GetEnumerator();       while (demoEnum.MoveNext()) {          string res = demoEnum.Current;     ... Read More

Check if SortedDictionary contains the specified key or not in C#

AmitDiwan
Updated on 06-Dec-2019 10:08:09

79 Views

To check if SortedDictionary contains the specified key or not, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Generic; public class Demo {    public static void Main() {       SortedDictionary sortedDict = 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

Check if Hashtable is synchronized C#

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

73 Views

To check if Hashtable is synchronized, 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("One", "Katie");       hash.Add("Two", "John");       hash.Add("Three", "Barry");       hash.Add("Four", "");       hash.Add("Five", "Harry");       hash.Add("Six", "F");       hash.Add("Seven", "Tom");       hash.Add("Eight", "Andy");       hash.Add("Nine", "I");       hash.Add("Ten", "Tim");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry entry in hash) { ... Read More

Advertisements