Found 26504 Articles for Server Side Programming

Get an enumerator that iterates through the StringDictionary in C#

AmitDiwan
Updated on 11-Dec-2019 07:13:32

105 Views

To get an enumerator that iterates through StringDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringDictionary strDict1 = new StringDictionary();       strDict1.Add("A", "John");       strDict1.Add("B", "Andy");       strDict1.Add("C", "Tim");       strDict1.Add("D", "Ryan");       strDict1.Add("E", "Kevin");       strDict1.Add("F", "Katie");       strDict1.Add("G", "Brad");       Console.WriteLine("StringDictionary1 elements...");       foreach(DictionaryEntry de in strDict1) {          Console.WriteLine(de.Key + " " + de.Value);       } ... Read More

foreach Loop in C#

AmitDiwan
Updated on 11-Dec-2019 07:11:40

532 Views

The foreach loop executes a statement or a block of statements for each element in an instance of the type that implements the System.Collections.IEnumerable or System.Collections.Generic.IEnumerable interface.ExampleLet us see an example of foreach loop − Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       LinkedList linkedList = new LinkedList();       linkedList.AddLast(25);       linkedList.AddLast(50);       linkedList.AddLast(100);       linkedList.AddLast(200);       linkedList.AddLast(400);       linkedList.AddLast(500);       linkedList.AddLast(550);       linkedList.AddLast(600);       linkedList.AddLast(800);       linkedList.AddLast(1200);       Console.WriteLine("Count ... Read More

Get an enumerator that iterates through the SortedSet in C#

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

107 Views

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

How to create a shallow copy of ArrayList in C#?

AmitDiwan
Updated on 11-Dec-2019 07:09:00

235 Views

To create a shallow copy of ArrayList in C#, 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);       ... Read More

How to create a ListDictionary in C#?

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

101 Views

To create a 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 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 in dict){ ... Read More

Check if every List element matches the predicate conditions in C#

AmitDiwan
Updated on 11-Dec-2019 07:06:51

363 Views

To check if every List element matches the predicate conditions, 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) {       List list = new List();       list.Add(200);       list.Add(215);       list.Add(310);       list.Add(500);       list.Add(600);       Console.WriteLine("List elements...");       foreach (int i in list) {          Console.WriteLine(i);       } ... Read More

Intersection of two HashSets in C#

AmitDiwan
Updated on 11-Dec-2019 07:02:09

519 Views

To find the intersection of two HashSets, 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("AB");       set1.Add("CD");       set1.Add("EF");       set1.Add("AB");       set1.Add("IJ");       set1.Add("KL");       set1.Add("EF");       set1.Add("OP");       Console.WriteLine("Elements in HashSet1");       foreach(string val in set1){          Console.WriteLine(val);       }       HashSet set2 = new HashSet();       set2.Add("EF"); ... Read More

Intersection of SortedSet with a collection in C#

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

146 Views

To get the intersection of SortedSet with a Collection, the code is as follow −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedSet set1 = new SortedSet();       set1.Add(100);       set1.Add(200);       set1.Add(300);       SortedSet set2 = new SortedSet();       set2.Add(450);       set2.Add(200);       set2.Add(650);       set2.Add(300);       set2.Add(800);       Console.WriteLine("Does it contain the same elements? = "+set1.SetEquals(set2));       set1.IntersectWith(set2);       Console.WriteLine("Resultant SortedSet...");       foreach(int ... Read More

Insert into OrderedDictionary with key and value at specified index in C#

AmitDiwan
Updated on 11-Dec-2019 06:53:56

332 Views

To insert into OrderedDictionary with key and value at specified index, 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");       Console.WriteLine("OrderedDictionary elements...");       foreach(DictionaryEntry d in dict){          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("Count of elements in OrderedDictionary = " + dict.Count); ... Read More

Insert at the specified index in StringCollection in C#

AmitDiwan
Updated on 11-Dec-2019 06:48:14

162 Views

To insert at the specified index in StringCollection, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringCollection strCol = new StringCollection();       strCol.Add("Accessories");       strCol.Add("Books");       strCol.Add("Electronics");       Console.WriteLine("StringCollection elements...");       foreach (string res in strCol){          Console.WriteLine(res);       }       strCol.Insert(2, "Headphone");       Console.WriteLine("StringCollection elements...UPDATED");       foreach (string res in strCol){          Console.WriteLine(res);       }    } }OutputThis will ... Read More

Advertisements