Found 2628 Articles for Csharp

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

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

131 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

41 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

134 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

73 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

77 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

How to get First Element of the Tuple in C#?

AmitDiwan
Updated on 06-Dec-2019 07:22:50

663 Views

To get the first element of the Tuple, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 5th = "+tuple1.Item5);       Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item5);       Console.WriteLine("Tuple1 Item 1st ... Read More

Check if two ListDictionary objects are equal in C#

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

90 Views

To check if two ListDictionary objects are equal, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       ListDictionary dict1 = new ListDictionary();       dict1.Add("A", "Books");       dict1.Add("B", "Electronics");       dict1.Add("C", "Smart Wearables");       dict1.Add("D", "Pet Supplies");       dict1.Add("E", "Clothing");       dict1.Add("F", "Footwear");       Console.WriteLine("ListDictionary1 elements...");       foreach(DictionaryEntry d in dict1){          Console.WriteLine(d.Key + " " + d.Value);       }       ListDictionary dict2 ... Read More

Check if two List objects are equal in C#

AmitDiwan
Updated on 06-Dec-2019 07:09:29

287 Views

To check if two List objects are equal, 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

Remove the element with the specified key from the Hashtable in C#

AmitDiwan
Updated on 06-Dec-2019 07:06:52

80 Views

To remove the element with the specified key from 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(10);       hash.Add("1", "A");       hash.Add("2", "B");       hash.Add("3", "C");       hash.Add("4", "D");       hash.Add("5", "E");       hash.Add("6", "F");       hash.Add("7", "G");       hash.Add("8", "H");       hash.Add("9", "I");       hash.Add("10", "J");       Console.WriteLine("Hashtable Key and Value pairs...");       foreach(DictionaryEntry ... Read More

How to get Fifth Element of the Tuple in C#?

AmitDiwan
Updated on 06-Dec-2019 07:03:47

72 Views

To get the fifth element of the Tuple, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 5th = "+tuple1.Item5);       Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item5);    } }OutputThis will produce the ... Read More

Advertisements