Found 2628 Articles for Csharp

Copying the Collection elements to an array in C#

AmitDiwan
Updated on 10-Dec-2019 10:45:09

71 Views

To copy the Collection elements to an array, 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("One");       col.Add("Two");       col.Add("Three");       col.Add("Four");       col.Add("Five");       col.Add("Six");       col.Add("Seven");       col.Add("Eight");       Console.WriteLine("Collection....");       foreach(string str in col){          Console.WriteLine(str);       }       string[] strArr = new string[10];       col.CopyTo(strArr, 2); ... Read More

Copying BitArray elements to an Array in C#

AmitDiwan
Updated on 10-Dec-2019 10:41:10

192 Views

To copy BitArray elements to an Array, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       BitArray arr = new BitArray(2);       arr[0] = false;       arr[1] = true;       Console.WriteLine("Elements in BitArray...");       foreach (bool res in arr){          Console.WriteLine(res);       }       bool[] boolArr = new bool[2];       boolArr[0] = true;       boolArr[1] = false;       arr.CopyTo(boolArr, 0);       Console.WriteLine("Array...");     ... Read More

Copy the Stack to an Array in C#

AmitDiwan
Updated on 10-Dec-2019 10:35:19

137 Views

To copy the stack to an array, 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(10);       stack.Push(20);       stack.Push(30);       stack.Push(40);       stack.Push(50);       stack.Push(60);       stack.Push(70);       stack.Push(80);       stack.Push(90);       stack.Push(100);       Console.WriteLine("Displaying the stack...");       foreach(int val in stack){          Console.WriteLine(val);       }       int[] ... Read More

Copy the entire LinkedList to Array in C#

AmitDiwan
Updated on 10-Dec-2019 10:31:13

253 Views

To copy the entire LinkedList to Array, 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(100);       list.AddLast(200);       list.AddLast(300);       int[] strArr = new int[5];       list.CopyTo(strArr, 0);       foreach(int str in strArr){          Console.WriteLine(str);       }    } }OutputThis will produce the following output −100 200 300 0 0ExampleLet us now see another example − Live Demousing System; using System.Collections.Generic; public class ... Read More

Copy the elements of collection over a range of elements in ArrayList in C#

AmitDiwan
Updated on 10-Dec-2019 10:28:47

194 Views

To copy the elements of the collection over a range of elements in ArrayList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       ArrayList arrList = new ArrayList();       arrList.Add("A");       arrList.Add("B");       arrList.Add("C");       arrList.Add("D");       Console.WriteLine("ArrayList elements...");       for (int i = 0; i < arrList.Count; i++) {          Console.WriteLine("" + arrList[i]);       }       string[] str = { "Demo", "Text" };       arrList.SetRange(0, ... Read More

Copy StringDictionary to Array at the specified index in C#

AmitDiwan
Updated on 10-Dec-2019 10:26:27

68 Views

To copy StringDictionary to Array at the 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(){       StringDictionary strDict = new StringDictionary();       strDict.Add("1", "SUV");       strDict.Add("2", "AUV");       strDict.Add("3", "Electric Car");       strDict.Add("4", "Utility Vehicle");       strDict.Add("5", "Hatchback");       strDict.Add("6", "Compact car");       strDict.Add("7", "MUV");       strDict.Add("8", "Crossover");       strDict.Add("9", "Covertible");       strDict.Add("10", "Quadricycle");       DictionaryEntry[] arr = { new DictionaryEntry(), ... Read More

Copy StringCollection at the specified index of array in C#

AmitDiwan
Updated on 10-Dec-2019 10:20:29

62 Views

To copy StringCollection at the specified index of the array, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main(){       StringCollection strCol = new StringCollection();       String[] strArr = new String[] { "Tim", "Tom", "Sam", "Mark", "Katie", "Jacob"};       Console.WriteLine("Elements...");       for (int i = 0; i < strArr.Length; i++) {          Console.WriteLine(strArr[i]);       }       strCol.AddRange(strArr);       String[] arr = new String[strCol.Count];       strCol.CopyTo(arr, 0);       Console.WriteLine("Elements...after copying ... Read More

Copy OrderedDictionary elements to Array instance at the specified index in C#

AmitDiwan
Updated on 10-Dec-2019 10:17:30

76 Views

To copy OrderedDictionary elements to Array instance at the 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(1, "Harry");       dict.Add(2, "Mark");       dict.Add(3, "John");       dict.Add(4, "Jacob");       dict.Add(5, "Tim");       Console.WriteLine("OrderedDictionary elements...");       foreach(DictionaryEntry d in dict){          Console.WriteLine(d.Key + " " + d.Value);       }       DictionaryEntry[] dictArr = new DictionaryEntry[dict.Count]; ... Read More

Copy ListDictionary to Array instance at the specified index in C#

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

62 Views

To copy ListDictionary to Array instance at the 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(){       ListDictionary dict = new ListDictionary();       dict.Add(1, "Harry");       dict.Add(2, "Mark");       dict.Add(3, "John");       dict.Add(4, "Jacob");       dict.Add(5, "Tim");       dict.Add(6, "Sam");       dict.Add(7, "Tom");       dict.Add(8, "Kevin");       Console.WriteLine("ListDictionary elements...");       foreach(DictionaryEntry d in dict){          Console.WriteLine(d.Key + " " + ... Read More

Adding the specified key and value into HybridDictionary in C#

AmitDiwan
Updated on 10-Dec-2019 10:09:25

59 Views

To add the specified key and value into 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 dict = new HybridDictionary();       dict.Add("A", "Bags");       dict.Add("B", "Electronics");       dict.Add("C", "Smart Wearables");       dict.Add("D", "Pet Supplies");       Console.WriteLine("HybridDictionary elements...");       foreach(DictionaryEntry d in dict){          Console.WriteLine(d.Key + " " + d.Value);       }       Console.WriteLine("Is the HybridDictionary having fixed size? = "+dict.IsFixedSize);       ... Read More

Advertisements