Copy Entire ArrayList to 1-D Array Starting at Specified Index in C#

AmitDiwan
Updated on 10-Dec-2019 11:14:33

109 Views

To copy the entire ArrayList to a 1-D array starting at the specified index, 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("PQ");       list.Add("RS");       list.Add("TU");       list.Add("UV");       list.Add("WX");       list.Add("YZ");       Console.WriteLine("ArrayList elements...");       for (int i = 0; i < list.Count; i++) {          Console.WriteLine(list[i]);       }       String[] strArr = new String[6] ... Read More

Copy Elements of ArrayList to a New Array in C#

AmitDiwan
Updated on 10-Dec-2019 11:08:53

167 Views

To copy the elements of ArrayList to a new array, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       ArrayList list = new ArrayList(10);       list.Add("A");       list.Add("B");       list.Add("C");       list.Add("D");       list.Add("E");       list.Add("F");       list.Add("G");       list.Add("H");       list.Add("I");       list.Add("J");       Console.WriteLine("ArrayList elements...");       foreach(string str in list){          Console.WriteLine(str);       }     ... Read More

Create a SortedList in C#

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

147 Views

To create 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){          Console.WriteLine("Key = ... Read More

Create Shallow Copy of BitArray in C#

AmitDiwan
Updated on 10-Dec-2019 11:00:20

163 Views

To create a shallow copy of the BitArray, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       BitArray arr1 = new BitArray(5);       arr1[0] = false;       arr1[1] = true;       Console.WriteLine("BitArray length = "+arr1.Length);       Console.WriteLine("BitArray first element = "+arr1.Get(0));       Console.WriteLine("BitArray second element = "+arr1.Get(1));       BitArray arr2 = (BitArray)arr1.Clone();       Console.WriteLine("BitArray2 length = "+arr2.Length);       Console.WriteLine("BitArray2 first element = "+arr2.Get(0));       Console.WriteLine("BitArray2 second element = "+arr2.Get(1)); ... Read More

Copy ArrayList to One-Dimensional Array in C#

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

232 Views

To copy the entire ArrayList to a one-dimensional array, 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("AB");       list.Add("BC");       list.Add("CD");       list.Add("EF");       list.Add("GH");       list.Add("IJ");       list.Add("KL");       list.Add("MN");       String[] strArr = new String[10];       Console.WriteLine("ArrayList...");       foreach(Object obj in list)       Console.WriteLine("{0}", obj);       list.CopyTo(strArr);       Console.WriteLine("String ... Read More

Copy a String into Another String in C#

AmitDiwan
Updated on 10-Dec-2019 10:52:48

511 Views

To copy a String into another String, the code is as follows −Example Live Demousing System; public class Demo {    static public void Main(){       string str1 = "Kevin";       string str2 = String.Copy(str1);       Console.WriteLine("String1 = "+str1);       Console.WriteLine("String2 = "+str2);    } }OutputThis will produce the following output −String1 = Kevin String2 = KevinExampleLet us now see another example − Live Demousing System; public class Demo {    static public void Main(){       string str1 = "Maisie";       string str2 = "Ryan";       Console.WriteLine("String1 (Before ... Read More

Check If List Contains Specified Element in C#

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

637 Views

To check whether a List contains a specified element, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args){       List list1 = new List();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");       list1.Add("Four");       list1.Add("Five");       Console.WriteLine("Elements in List1...");       foreach (string res in list1){          Console.WriteLine(res);       }       List list2 = new List();       list2.Add("India");       list2.Add("US");       list2.Add("UK"); ... Read More

Copy Collection Elements to an Array in C#

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

135 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

Copy BitArray Elements to an Array in C#

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

284 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 Stack to Array in C#

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

215 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

Advertisements