Found 2587 Articles for Csharp

How to copy a String into another String in C#

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

474 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

How to check whether a List contains a specified element in C#

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

593 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

Copying the Collection elements to an array in C#

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

114 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

256 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

193 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

370 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

274 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

126 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

121 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

137 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

Advertisements