Found 26504 Articles for Server Side Programming

Bitwise exclusive OR operation between the elements of BitArray in C#

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

114 Views

Let us see how to implement Bitwise exclusive OR operation between 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...");       foreach (bool ... Read More

Add an object to the end of the ArrayList in C#

AmitDiwan
Updated on 06-Dec-2019 08:07:13

139 Views

To add an object to the end of the ArrayList, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args){       ArrayList list = new ArrayList();       list.Add("Tim");       list.Add("Katie");       list.Add("Amy");       list.Add("Carlos");       list.Add("Chris");       list.Add("Jason");       Console.WriteLine("Elements in ArrayList...");       foreach (string res in list){          Console.WriteLine(res);       }    } }OutputThis will produce the following output −Elements in ArrayList... Tim Katie Amy Carlos ... Read More

How to create a SortedSet in C#?

AmitDiwan
Updated on 06-Dec-2019 08:02:33

103 Views

To create a SortedSet, 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("AB");       set1.Add("BC");       set1.Add("CD");       set1.Add("EF");       Console.WriteLine("Elements in SortedSet1...");       foreach (string res in set1){          Console.WriteLine(res);       }       SortedSet set2 = new SortedSet();       set2.Add("BC");       set2.Add("CD");       set2.Add("DE");       set2.Add("EF");       set2.Add("AB");     ... Read More

How to check current state of a thread in C#?

AmitDiwan
Updated on 06-Dec-2019 07:58:44

270 Views

To check the current state of a thread, the code is as follows −Example Live Demousing System; using System.Threading; public class Demo {    public static void Main(){       Thread thread = new Thread(new ThreadStart(demo1));       ThreadPool.QueueUserWorkItem(new WaitCallback(demo2));       Console.WriteLine("Current state of Thread = "+thread.ThreadState);       Console.WriteLine("ManagedThreadId = "+thread.ManagedThreadId);    }    public static void demo1(){       Thread.Sleep(2000);    }    public static void demo2(object stateInfo){       Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);    } }OutputThis will produce the following output −Current state of Thread = Unstarted ... Read More

How to add key/value pairs in SortedList in C#?

AmitDiwan
Updated on 06-Dec-2019 07:54:46

278 Views

To add key/value pairs in SortedList, 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", "Jacob");       list.Add("B", "Sam");       list.Add("C", "Tom");       list.Add("D", "John");       list.Add("E", "Tim");       list.Add("F", "Mark");       list.Add("G", "Gary");       list.Add("H", "Nathan");       list.Add("I", "Shaun");       list.Add("J", "David");       ICollection col1 = list.Values;       Console.WriteLine("Values...");       foreach(string s ... Read More

Getting the unique identifier for the current managed thread in C#

AmitDiwan
Updated on 06-Dec-2019 07:51:15

200 Views

To get the unique identifier for the currently managed thread, the code is as follows −Example Live Demousing System; using System.Threading; public class Demo {    public static void Main(){       Thread thread = new Thread(new ThreadStart(demo1));       ThreadPool.QueueUserWorkItem(new WaitCallback(demo2));       Console.WriteLine("ManagedThreadId = "+thread.ManagedThreadId);    }    public static void demo1(){       Thread.Sleep(2000);    }    public static void demo2(object stateInfo){       Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);    } }OutputThis will produce the following output −ManagedThreadId = 3 Thread belongs to managed thread pool? = TrueExampleLet us now ... Read More

Getting the Type of the Tuple’s Element in C#

AmitDiwan
Updated on 06-Dec-2019 07:48:05

85 Views

To get the type of the Tuple’s element, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(150, 1500, Tuple.Create(50, 100));       var tuple2 = Tuple.Create(150, 1500, Tuple.Create(100, 200));       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("Type of Tuple1 = "+tuple1.GetType());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Type of Tuple1 = "+tuple2.GetType());    } }OutputThis will produce the following output −Is Tuple1 equal to ... Read More

Getting the type of the current instance in C#

AmitDiwan
Updated on 06-Dec-2019 07:42:28

215 Views

To get the type of the current instance, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       string s = "Demo";       Console.WriteLine("String = " +s);       Console.WriteLine("String Type = " +s.GetType());    } }OutputThis will produce the following output −String = Demo String Type = System.StringExampleLet us now see another example − Live Demousing System; public class Demo {    public static void Main(){       double val1 = 5.5;       int val2 = 10;       short val3 = 2; ... Read More

Getting an enumerator for a range of elements in the ArrayList in C#

AmitDiwan
Updated on 06-Dec-2019 07:39:34

146 Views

To get an enumerator for a range of elements in the 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(100);       arrList.Add(200);       arrList.Add(300);       arrList.Add(400);       arrList.Add(500);       Console.WriteLine("Display elements in a range...");       IEnumerator demoEnum = arrList.GetEnumerator(1, 3);       while (demoEnum.MoveNext()) {          Object ob = demoEnum.Current;          Console.WriteLine(ob);       }    } ... Read More

Gets or sets the value of the bit at a specific position in the BitArray in C#

AmitDiwan
Updated on 06-Dec-2019 07:36:21

125 Views

To get or set the value of the bit at a specific position 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("BitArray1 first element = "+arr1.Get(0));       arr2[0] = false;       arr2[1] = true;       Console.WriteLine("BitArray2 length = "+arr2.Length);       ... Read More

Advertisements