Found 2628 Articles for Csharp

Get or set the number of elements in the BitArray in C#

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

61 Views

To get or set the number of elements in 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(2);       BitArray arr2 = new BitArray(2);       arr1[0] = false;       arr1[1] = true;       Console.WriteLine("BitArray1 length = "+arr1.Length);       Console.WriteLine("Elements in BitArray1...");       foreach (bool res in arr1) {          Console.WriteLine(res);       }       arr2[0] = false;       arr2[1] ... Read More

Union of SortedSet to a collection in C#

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

77 Views

To compute the Union of SortedSet to a Collection, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       SortedSet set1 = new SortedSet();       set1.Add(50);       set1.Add(100);       set1.Add(150);       Console.WriteLine("SortedSet1 elements...");       foreach(int ele in set1) {          Console.WriteLine(ele);       }       SortedSet set2 = new SortedSet();       set2.Add(100);       set2.Add(150);       set2.Add(200);       set2.Add(250);       Console.WriteLine("SortedSet2 elements..."); ... Read More

Bitwise OR operation between the elements of BitArray in C#

AmitDiwan
Updated on 10-Dec-2019 06:07:37

53 Views

Let us see how to implement Bitwise OR operation between the elements of BitArray −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() {       BitArray arr1 = new BitArray(5);       BitArray arr2 = new BitArray(5);       arr1[0] = false;       arr1[1] = false;       arr2[0] = false;       arr2[1] = true;       Console.WriteLine("BitArray1 elements...");       foreach (bool res in arr1) {          Console.WriteLine(res);       }       Console.WriteLine("BitArray2 elements...");       ... Read More

Get or set the element at the specified index in ArrayList in C#

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

802 Views

To get or set the element at the specified index 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("Laptop");       arrList.Add("Desktop");       arrList.Add("Notebook");       arrList.Add("Ultrabook");       arrList.Add("Tablet");       arrList.Add("Headphone");       arrList.Add("Speaker");       Console.WriteLine("Elements in ArrayList...");       foreach(string str in arrList) {          Console.WriteLine(str);       }       Console.WriteLine("Element at index 5 = " ... Read More

Get or set the element at specified index in Collection in C#

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

168 Views

To get or set the element at specified index 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("Laptop");       col.Add("Desktop");       col.Add("Notebook");       col.Add("Ultrabook");       col.Add("Tablet");       col.Add("Headphone");       col.Add("Speaker");       Console.WriteLine("Elements in Collection...");       foreach(string str in col) {          Console.WriteLine(str);       }       Console.WriteLine("Element at index 3 = " + ... Read More

Get or Set at specified index in StringCollection in C#

AmitDiwan
Updated on 10-Dec-2019 05:58:23

83 Views

To get or set at 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]);    } }OutputThis will produce the following output −StringCollection elements... ... Read More

Check if SortedSet and a specified collection share common elements in C#

AmitDiwan
Updated on 10-Dec-2019 05:55:19

53 Views

To check if SortedSet and a specified collection share common element, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       SortedSet set1 = new SortedSet();       set1.Add(100);       set1.Add(200);       set1.Add(300);       set1.Add(400);       set1.Add(500);       set1.Add(600);       SortedSet set2 = new SortedSet();       set2.Add(100);       set2.Add(200);       set2.Add(300);       set2.Add(400);       set2.Add(500);       set2.Add(600);       Console.WriteLine("Does it ... Read More

Capacity of a SortedList in C#

AmitDiwan
Updated on 09-Dec-2019 06:27:26

93 Views

To get the capacity of 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){       ... Read More

Check whether the Unicode character is a separator character in C#

AmitDiwan
Updated on 09-Dec-2019 06:24:15

145 Views

To check whether the Unicode character is a separator character, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       bool res;       char val = ', ';       Console.WriteLine("Value = "+val);       res = Char.IsSeparator(val);       Console.WriteLine("Is the value a separator? = "+res);    } }OutputThis will produce the following output −Value = , Is the value a separator? = FalseExampleLet us now see another example − Live Demousing System; public class Demo {    public static void Main(){       ... Read More

Convert Decimal to equivalent 8-bit unsigned integer in C#

AmitDiwan
Updated on 09-Dec-2019 06:21:28

214 Views

To convert the value of the specified Decimal to the equivalent 8-bit unsigned integer, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       Decimal val1 = 6.59m;       Decimal val2 = 30.12m;       Decimal val3 = 69.34m;       Console.WriteLine("Decimal 1 = "+val1);       Console.WriteLine("Decimal 2 = "+val2);       Console.WriteLine("Decimal 3 = "+val3);       byte res1 = Decimal.ToByte(val1);       byte res2 = Decimal.ToByte(val2);       byte res3 = Decimal.ToByte(val3);       Console.WriteLine("Byte value1 (Decimal ... Read More

Advertisements