Found 26504 Articles for Server Side Programming

Get the TypeCode for value type Int32 in C#

AmitDiwan
Updated on 11-Dec-2019 07:33:57

142 Views

To get the TypeCode for value type Int32, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       int val1 = 100;       int val2 = 50;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("Are they equal? = "+val1.Equals(val2));         Console.WriteLine("HashCode for Value1 = "+val1.GetHashCode());       Console.WriteLine("HashCode for Value2 = "+val2.GetHashCode());       TypeCode type1 = val1.GetTypeCode();       TypeCode type2 = val2.GetTypeCode();       Console.WriteLine("TypeCode for Value1 = "+type1);   ... Read More

Convert Decimal to the equivalent 64-bit unsigned integer in C#

AmitDiwan
Updated on 11-Dec-2019 07:29:52

588 Views

To convert the value of the specified Decimal to the equivalent 64-bit unsigned integer, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       Decimal val = 99.29m;       Console.WriteLine("Decimal value = "+val);       ulong res = Decimal.ToUInt64(val);       Console.WriteLine("64-bit unsigned integer = "+res);    } }OutputThis will produce the following output −Decimal value = 99.29 64-bit unsigned integer = 99ExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main(){       Decimal val = 0.001m;       Console.WriteLine("Decimal value = ... Read More

Indicate whether this instance is equal to a specified object or UInt16 in C#

AmitDiwan
Updated on 11-Dec-2019 07:26:44

102 Views

To indicate whether this instance is equal to a specified object or UInt16, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       ushort val1 = 52;       ushort val2 = 10;       bool res = val1.Equals(val2);       Console.WriteLine("Return value (comparison) = "+res);       if (res)          Console.WriteLine("val1 = val2");       else          Console.WriteLine("val1 != val2");    } }OutputThis will produce the following output −Return value (comparison) = False val1 != val2ExampleLet us now ... Read More

ConvertDecimal to equivalent 32-bit unsigned integer in C#

AmitDiwan
Updated on 11-Dec-2019 07:25:14

446 Views

To convert the value of the specified Decimal to the equivalent 32-bit unsigned integer, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main() {       Decimal val = 0.001m;       Console.WriteLine("Decimal value = "+val);       uint res = Decimal.ToUInt32(val);       Console.WriteLine("32-bit unsigned integer = "+res);    } }OutputThis will produce the following output −Decimal value = 0.001 32-bit unsigned integer = 0ExampleLet us see another example − Live Demousing System; public class Demo {    public static void Main() {       Decimal val ... Read More

Get the number of key/value pairs in the Dictionary in C#

AmitDiwan
Updated on 11-Dec-2019 07:24:04

577 Views

To get the number of key/value pairs in the Dictionary, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary dict =       new Dictionary();       dict.Add("One", "Chris");       dict.Add("Two", "Steve");       dict.Add("Three", "Messi");       dict.Add("Four", "Ryan");       dict.Add("Five", "Nathan");       Console.WriteLine("Count of elements = "+dict.Count);       Console.WriteLine("Key/value pairs...");       foreach(KeyValuePair res in dict){          Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value);       ... Read More

Reinterpret 64-bit signed integer to a double-precision floating point number in C#

AmitDiwan
Updated on 11-Dec-2019 07:22:35

485 Views

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

Convert the value of the specified string to its equivalent Unicode character in C#

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

376 Views

To convert the value of the specified string to its equivalent Unicode character, the code is as follows −Example Live Demousing System; public class Demo {    public static void Main(){       bool res;       Char ch;       res = Char.TryParse("10", out ch);       Console.WriteLine(res);       Console.WriteLine(ch.ToString());    } }OutputThis will produce the following output −FalseExampleLet us now see another example − Live Demousing System; public class Demo {    public static void Main(){       bool res;       Char ch;       res = Char.TryParse("P", out ch);       Console.WriteLine(res);       Console.WriteLine(ch.ToString());    } }OutputThis will produce the following output −True P

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

380 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

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

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

285 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

2K+ 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

Advertisements