Found 2587 Articles for Csharp

Remove all the strings from the StringCollection in C#

AmitDiwan
Updated on 10-Dec-2019 07:09:38

138 Views

To remove all the strings from the StringCollection, the code is as follows −Example Live Demousing System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection stringCol = new StringCollection();       String[] arr = new String[] { "100", "200", "300", "400", "500" };       Console.WriteLine("Array elements...");       foreach (string res in arr) {          Console.WriteLine(res);       }       stringCol.AddRange(arr);       Console.WriteLine("Does the specified string is in the StringCollection? = "+stringCol.Contains("800"));       Console.WriteLine("Total number of elements = "+stringCol.Count); ... Read More

Removing all the elements from the List in C#

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

160 Views

To remove all the elements from 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 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");       ... Read More

Get the number of elements contained in Collection in C#

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

119 Views

To get the number of elements contained in Collection, 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("Andy");       col.Add("Kevin");       col.Add("John");       col.Add("Kevin");       col.Add("Mary");       col.Add("Katie");       col.Add("Barry");       col.Add("Nathan");       col.Add("Mark");       Console.WriteLine("Count of elements = "+ col.Count);       Console.WriteLine("Iterating through the collection...");       var enumerator = col.GetEnumerator();       while ... Read More

Gets or Sets the element at the specified index in the List in C#

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

150 Views

To get or set the element ate the specified index in 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("100");       list.Add("200");       list.Add("300");       list.Add("400");       list.Add("500");       list.Add("600");       list.Add("700");       list.Add("800");       list.Add("900");       list.Add("1000");       Console.WriteLine("Element at index 0 = " + list[0]);       Console.WriteLine("Element at index 1 ... Read More

Gets or sets the element at the specified index in StringCollection in C#

AmitDiwan
Updated on 10-Dec-2019 06:47:59

89 Views

To get or set the element 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();       String[] strArr = new String[] { "A", "B", "C", "D", "E", "F", "G", "H" };       Console.WriteLine("StringCollection elements...");       foreach (string str in strArr) {          Console.WriteLine(str);       }       strCol.AddRange(strArr);       Console.WriteLine("Element at 5th index = "+strCol[5]);       Console.WriteLine("Count of strings ... Read More

Gets an ICollection containing the values in the Hashtable in C#

AmitDiwan
Updated on 10-Dec-2019 06:42:56

104 Views

To get an ICollection containing the values in the Hashtable, 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("A", "Electronics");       hash.Add("B", "Appliances");       hash.Add("C", "Pet Supplies");       hash.Add("D", "Books");       hash.Add("E", "Toys");       hash.Add("F", "Footwear");       hash.Add("G", "Clothing");       ICollection col = hash.Keys;       foreach(string str in col)       Console.WriteLine(str + ": " + hash[str]);    } }OutputThis ... Read More

Get an ICollection containing the keys in the Hashtable C#

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

172 Views

To get an ICollection containing the keys in the Hashtable, 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("A", "Electronics");       hash.Add("B", "Appliances");       hash.Add("C", "Pet Supplies");       hash.Add("D", "Books");       hash.Add("E", "Toys");       hash.Add("F", "Footwear");       hash.Add("G", "Clothing");       ICollection col = hash.Keys;       foreach(string str in col)       Console.WriteLine(str + ": " + hash[str]);    } }OutputThis ... Read More

Get value of the bit at a specific position in BitArray in C#

AmitDiwan
Updated on 10-Dec-2019 06:36:57

188 Views

To get value of the bit at a specific position in BitArray, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       BitArray arr1 = new BitArray(2);       BitArray arr2 = new BitArray(2);       arr1[0] = false;       arr1[1] = true;       Console.WriteLine("BitArray1 length = "+arr1.Length);       Console.WriteLine("BitArray1 first element = "+arr1.Get(0));       arr2[0] = false;       arr2[1] = true;       Console.WriteLine("BitArray2 length = "+arr2.Length);       Console.WriteLine("Elements in BitArray2..."); ... Read More

Get or Set the value associated with specified key in Hashtable in C#

AmitDiwan
Updated on 10-Dec-2019 06:33:58

169 Views

To get or set the value associated with specified key in Hashtable, 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("1", "AB");       hash.Add("2", "BC");       hash.Add("3", "DE");       hash.Add("4", "EF");       hash.Add("5", "GH");       hash.Add("6", "IJ");       hash.Add("7", "KL");       hash.Add("8", "MN");       hash.Add("9", "OP");       hash.Add("10", "QR");       Console.WriteLine("Value at key 3 = "+hash["3"]);   ... Read More

Get or set the number of elements that the ArrayList can contain in C#

AmitDiwan
Updated on 10-Dec-2019 06:29:50

102 Views

To get or set the number of elements that the ArrayList can contain, 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(25);       arrList.Add(50);       arrList.Add(75);       arrList.Add(100);       arrList.Add(125);       arrList.Add(150);       arrList.Add(175);       arrList.Add(200);       arrList.Add(225);       arrList.Add(250);       Console.WriteLine("Elements in ArrayList...");       foreach(int i in arrList) {          Console.WriteLine(i); ... Read More

Advertisements