Check if HashSet and Specified Collection Contain Same Elements in C#

AmitDiwan
Updated on 06-Dec-2019 12:42:14

155 Views

To check if HashSet and the specified collection contain the same elements, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       HashSet set1 = new HashSet();       set1.Add("One");       set1.Add("Two");       set1.Add("Three");       set1.Add("Four");       set1.Add("Five");       set1.Add("Six");       set1.Add("Seven");       HashSet set2 = new HashSet();       set2.Add("One");       set2.Add("Two");       set2.Add("Three");       set2.Add("Four");       Console.WriteLine("Does it contains the same ... Read More

Get ICollection Containing Keys in OrderedDictionary in C#

AmitDiwan
Updated on 06-Dec-2019 12:40:43

165 Views

To get an ICollection containing keys in OrderedDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       OrderedDictionary dict = new OrderedDictionary();       dict.Add("1", "One");       dict.Add("2", "Two");       dict.Add("3", "Three");       dict.Add("4", "Four");       dict.Add("5", "Five");       dict.Add("6", "Six");       dict.Add("7", "Seven");       dict.Add("8", "Eight");       ICollection col = dict.Keys;       String[] strKeys = new String[dict.Count];       col.CopyTo(strKeys, 0);     ... Read More

Get Underlying Type of Current Enumeration in C#

AmitDiwan
Updated on 06-Dec-2019 12:36:43

219 Views

To return the underlying type of the current enumeration type, the code is as follows −Example Live Demousing System; public class Demo {    enum Vehicle {Car, Bus, Bike, Airplane}    public static void Main() {       try {          Vehicle v = Vehicle.Bike;          Type type = v.GetType();          string[] str = type.GetEnumNames();          Console.WriteLine("GetEnumName() to return the constant name = " + str);          Type type2 = type.GetEnumUnderlyingType();          Console.Write("Enum Underlying type = "+type2);          Console.WriteLine("Listing ... Read More

Get Names of Members of Current Enumeration Type in C#

AmitDiwan
Updated on 06-Dec-2019 12:33:51

74 Views

To get the names of the members of the current enumeration type, the code is as follows −Example Live Demousing System; public class Demo {    enum Vehicle {Car, Bus, Bike}    public static void Main() {       try {          Type type = typeof(string);          string[] str = type.GetEnumNames();          Console.WriteLine("GetEnumName() to return the constant name = " + str);          Console.WriteLine("Listing constants ..");          for (int i = 0; i < str.Length; i++)          Console.Write("{0} ", str[i]);     ... Read More

Convert Windows File Time to Local Time in C#

AmitDiwan
Updated on 06-Dec-2019 12:32:33

258 Views

To convert the specified Windows file time to an equivalent local time, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       DateTimeOffset offset = DateTimeOffset.FromFileTime(0);       Console.WriteLine("DateTimeOffset = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ",offset);    } }OutputThis will produce the following output −DateTimeOffset = 01 January 1601, 12:00:00ExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       DateTimeOffset offset = DateTimeOffset.FromFileTime(200000000);       Console.WriteLine("DateTimeOffset = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ",offset);    } }OutputThis will produce the following output −DateTimeOffset = 01 January 1601, 12:00:20

Check If a Thread Belongs to Managed Thread Pool in C#

AmitDiwan
Updated on 06-Dec-2019 12:31:21

214 Views

To check if a thread belongs to managed thread pool or not, 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(demo));       thread.Start();    }    public static void demo() {       Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);    } }OutputThis will produce the following output −Thread belongs to managed thread pool? = FalseExampleLet us see another example −using System; using System.Threading; public class Demo {    public static void Main() {       ThreadPool.QueueUserWorkItem(new WaitCallback(demo));    }    public ... Read More

Check If an Array is Synchronized in C#

AmitDiwan
Updated on 06-Dec-2019 12:29:37

169 Views

To check if an array is synchronized or not, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       string[] products = new string[] { };       Console.WriteLine("One or more planets begin with 'E'? = {0}",       Array.Exists(products, ele => ele.StartsWith("E")));       Console.WriteLine("Is the array having fixed size? = " + products.IsFixedSize);       Console.WriteLine("Is the array read only? = " + products.IsReadOnly);       Console.WriteLine("Is the array synchronized? = " + products.IsSynchronized);    } }OutputThis will produce the following output ... Read More

Check If the BitArray is Read-Only in C#

AmitDiwan
Updated on 06-Dec-2019 12:27:46

137 Views

To check if the BitArray is read-only, 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("Elements in BitArray1...");       foreach (bool res in arr1) {          Console.WriteLine(res);       }       arr2[0] = false;       arr2[1] = true;       Console.WriteLine("Elements in BitArray2...");       ... Read More

Get Object at the Top of the Stack in C#

AmitDiwan
Updated on 06-Dec-2019 12:19:47

330 Views

To get object at the top of the Stack, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       Stack stack = new Stack();       stack.Push("A");       stack.Push("B");       stack.Push("C");       stack.Push("D");       stack.Push("E");       stack.Push("F");       stack.Push("G");       stack.Push("H");       stack.Push("I");       stack.Push("J");       Console.WriteLine("Count of elements = "+stack.Count);       Console.WriteLine("Element at the top of stack = " + stack.Peek());    } ... Read More

Get IDictionaryEnumerator Object in OrderedDictionary in C#

AmitDiwan
Updated on 06-Dec-2019 12:14:19

140 Views

To get an IDictionaryEnumerator object in OrderedDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       OrderedDictionary dict = new OrderedDictionary();       dict.Add("1", "One");       dict.Add("2", "Two");       dict.Add("3", "Three");       dict.Add("4", "Four");       dict.Add("5", "Five");       dict.Add("6", "Six");       dict.Add("7", "Seven");       dict.Add("8", "Eight");       IDictionaryEnumerator demoEnum = dict.GetEnumerator();       while (demoEnum.MoveNext()) {          Console.WriteLine("Key = " + demoEnum.Key + ... Read More

Advertisements