Found 2628 Articles for Csharp

Convert the specified double-precision floating point number to a 64-bit signed integer in C#

AmitDiwan
Updated on 11-Dec-2019 07:20:20

301 Views

To convert the specified double-precision floating point number to a 64-bit signed integer, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       double d = 5.646587687;       Console.Write("Value = "+d);       long res = BitConverter.DoubleToInt64Bits(d);       Console.Write("64-bit signed integer = "+res);    } }OutputThis will produce the following output −Value = 5.646587687 64-bit signed integer = 4618043510978159912ExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       double d = 0.001;       Console.Write("Value = "+d);   ... Read More

Exception in C#

AmitDiwan
Updated on 11-Dec-2019 07:19:13

238 Views

An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four keywords −try − A try block identifies a block of code for which particular exceptions are activated. It is followed by one or more catch blocks.catch − A program catches an exception with an exception handler at the place in a ... Read More

Convert the value of the current DateTime object to a Windows file time in C#

AmitDiwan
Updated on 11-Dec-2019 07:17:06

201 Views

To convert the value of the current DateTime object to a Windows file time, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       DateTime d = DateTime.Now;       Console.WriteLine("Date = {0}", d);       long res = d.ToFileTime();       Console.WriteLine("Windows file time = {0}", res);    } }OutputThis will produce the following output −Date = 10/16/2019 8:17:26 AM Windows file time = 132156874462559390ExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 05, 10, 6, ... Read More

How to use strings in switch statement in C#

AmitDiwan
Updated on 11-Dec-2019 07:15:20

1K+ Views

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.ExampleHere is an example to use strings in a switch statement − Live Demousing System; public class Demo {    public static void Main(String[] args){       string grades = "A1";       switch (grades) {          case "A1":             Console.WriteLine("Very good!");             break;          case "A2":       ... Read More

Get an enumerator that iterates through the StringDictionary in C#

AmitDiwan
Updated on 11-Dec-2019 07:13:32

63 Views

To get an enumerator that iterates through StringDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringDictionary strDict1 = new StringDictionary();       strDict1.Add("A", "John");       strDict1.Add("B", "Andy");       strDict1.Add("C", "Tim");       strDict1.Add("D", "Ryan");       strDict1.Add("E", "Kevin");       strDict1.Add("F", "Katie");       strDict1.Add("G", "Brad");       Console.WriteLine("StringDictionary1 elements...");       foreach(DictionaryEntry de in strDict1) {          Console.WriteLine(de.Key + " " + de.Value);       } ... Read More

foreach Loop in C#

AmitDiwan
Updated on 11-Dec-2019 07:11:40

361 Views

The foreach loop executes a statement or a block of statements for each element in an instance of the type that implements the System.Collections.IEnumerable or System.Collections.Generic.IEnumerable interface.ExampleLet us see an example of foreach loop − Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       LinkedList linkedList = new LinkedList();       linkedList.AddLast(25);       linkedList.AddLast(50);       linkedList.AddLast(100);       linkedList.AddLast(200);       linkedList.AddLast(400);       linkedList.AddLast(500);       linkedList.AddLast(550);       linkedList.AddLast(600);       linkedList.AddLast(800);       linkedList.AddLast(1200);       Console.WriteLine("Count ... Read More

Get an enumerator that iterates through the SortedSet in C#

AmitDiwan
Updated on 11-Dec-2019 07:10:21

53 Views

To get an enumerator that iterates through the 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");       ... Read More

How to create a shallow copy of ArrayList in C#?

AmitDiwan
Updated on 11-Dec-2019 07:09:00

162 Views

To create a shallow copy of ArrayList in C#, the code is as follows −Example Live Demousing System; using System.Collections; public class Demo {    public static void Main(){       ArrayList list = new ArrayList();       list.Add("One");       list.Add("Two");       list.Add("Three");       list.Add("Four");       list.Add("Five");       list.Add("Six");       list.Add("Seven");       list.Add("Eight");       Console.WriteLine("ArrayList elements...");       foreach(string str in list){          Console.WriteLine(str);       }       Console.WriteLine("ArrayList is read-only? = "+list.IsReadOnly);       ... Read More

How to create a ListDictionary in C#?

AmitDiwan
Updated on 11-Dec-2019 07:05:05

46 Views

To create a ListDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       ListDictionary dict = new ListDictionary();       dict.Add("1", "SUV");       dict.Add("2", "Sedan");       dict.Add("3", "Utility Vehicle");       dict.Add("4", "Compact Car");       dict.Add("5", "SUV");       dict.Add("6", "Sedan");       dict.Add("7", "Utility Vehicle");       dict.Add("8", "Compact Car");       dict.Add("9", "Crossover");       dict.Add("10", "Electric Car");       Console.WriteLine("ListDictionary elements...");       foreach(DictionaryEntry d in dict){ ... Read More

Check if every List element matches the predicate conditions in C#

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

269 Views

To check if every List element matches the predicate conditions, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    private static bool demo(int i) {       return ((i % 10) == 0);    }    public static void Main(String[] args) {       List list = new List();       list.Add(200);       list.Add(215);       list.Add(310);       list.Add(500);       list.Add(600);       Console.WriteLine("List elements...");       foreach (int i in list) {          Console.WriteLine(i);       } ... Read More

Advertisements