Found 2628 Articles for Csharp

Convert the specified Windows file time to an equivalent local time in C#

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

184 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 or not in C#

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

131 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 or not in C#

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

92 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

61 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

239 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 an IDictionaryEnumerator object in OrderedDictionary in C#

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

85 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

Check if SortedSet and the specified collection contain the same elements in C#

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

66 Views

To check if SortedSet and the specified collection contain the same elements, the code is as follows −Exampleusing 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);       SortedSet set2 = new SortedSet();       set2.Add(450);       set2.Add(550);       set2.Add(650);       set2.Add(750);       set2.Add(800);       Console.WriteLine("Does it contain the same elements? = "+set1.SetEquals(set2));    } }OutputThis will produce the following output −Does it contain the same elements? = FalseExampleLet us ... Read More

Getting the Values in a SortedList object in C#

AmitDiwan
Updated on 06-Dec-2019 11:59:40

69 Views

To get the values in a SortedList object, the code is as follows −Exampleusing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList list = new SortedList();       list.Add(1, "One");       list.Add(2, "Two");       list.Add(3, "Three");       list.Add(4, "Four");       list.Add(5, "Five");       ICollection col1 = list.Values;       Console.WriteLine("Values...");       foreach(string s in col1)       Console.WriteLine(s);       ICollection col2 = list.Keys;       Console.WriteLine("Keys...");       foreach(int s in ... Read More

Getting the value at the specified index of a SortedList object in C#

AmitDiwan
Updated on 06-Dec-2019 11:55:44

59 Views

To get the value at the specified index 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", "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");       Console.WriteLine("Value at index 2 = "+list.GetByIndex(2));       Console.WriteLine("Value at index 5 = "+list.GetByIndex(5));       Console.WriteLine("Value at index ... Read More

Check if the ArrayList is read-only in C#

AmitDiwan
Updated on 06-Dec-2019 11:50:58

70 Views

To check if the ArrayList is read-only, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("ABC");       list1.Add("BCD");       list1.Add("CDE");       list1.Add("DEF");       list1.Add("EFG");       list1.Add("GHI");       list1.Add("HIJ");       list1.Add("IJK");       list1.Add("JKL");       list1.Add("KLM");       Console.WriteLine("Elements in ArrayList...");       foreach (string res in list1) {          Console.WriteLine(res);       } ... Read More

Advertisements