Found 2628 Articles for Csharp

Get the number of elements contained in Collection in C#

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

71 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

94 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

58 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

72 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

132 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

129 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

125 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

54 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

Getting the list of Values of a SortedList object in C#

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

71 Views

To get the list of values of a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list = new SortedList();       list.Add("A", 1);       list.Add("B ", 2);       list.Add("C ", 3);       list.Add("D", 4);       list.Add("E", 5);       list.Add("F", 6);       list.Add("G", 7);       list.Add("H", 8);       Console.WriteLine("SortedList elements...");       foreach(DictionaryEntry d in list) {          Console.WriteLine(d.Key + ... Read More

Getting the list of keys of a SortedList object in C#

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

580 Views

To get the list of keys of a SortedList object, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list1 = new SortedList();       list1.Add("One", 1);       list1.Add("Two ", 2);       list1.Add("Three ", 3);       list1.Add("Four", 4);       list1.Add("Five", 5);       list1.Add("Six", 6);       list1.Add("Seven ", 7);       list1.Add("Eight ", 8);       list1.Add("Nine", 9);       list1.Add("Ten", 10);       Console.WriteLine("SortedList1 elements...");     ... Read More

Advertisements