The Hash Custom Specifier in C#

Arjun Thakur
Updated on 23-Jun-2020 08:50:10

230 Views

The "#" custom format specifier works as a digit-placeholder symbol.If the value to be formatted has a digit in the position where the "#" symbol appears in the format string, then that digit is copied to the resultant string.We have set a double type here.double d; d = 4.2;Now, let us use the “#” custom specifier.d.ToString("#.##", CultureInfo.InvariantCulture)Here are other examples.Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       double d;       d = 4.2;       Console.WriteLine(d.ToString("#.##", CultureInfo.InvariantCulture));       Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:#.##}", d));       d = 345; ... Read More

ArgumentNullException in C#

George John
Updated on 23-Jun-2020 08:49:16

808 Views

The exception thrown when a null reference is passed to a method that does not accept it as a valid argument.Let us see an example.When we set a null parameter to int.Parse() method, then ArgumentNullException is thrown as shown below −Exampleusing System; class Demo {    static void Main() {       string val = null;       int res = int.Parse(val); // error is thrown    } }OutputThe following error is thrown when the above program is compiled since we have passed a null value.Unhandled Exception: System.ArgumentNullException: Value cannot be null.

Convert Int32 Value to Decimal in C#

Samual Sam
Updated on 23-Jun-2020 08:48:26

3K+ Views

To convert an Int32 value to a decimal, use the Convert.ToDecimal() method.Int32 represents a 32-bit signed integer.Let’s say the following is our Int32 value.int val = 2923;Now to convert it to decimal.decimal decVal = Convert.ToDecimal(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       int val = 2923;       decimal decVal = Convert.ToDecimal(val);       Console.WriteLine("Converted Int32 {0} to decimal {1:N2} value ", val, decVal);    } }OutputConverted Int32 2923 to decimal 2,923.00 value

Convert Byte Value to Int32 Value in C#

Chandu yadav
Updated on 23-Jun-2020 08:47:57

8K+ Views

To convert a Byte value to an Int32 value, use the Convert.ToInt32() method.Int32 represents a 32-bit signed integer.Let’s say the following is our Byte value.byte val = Byte.MaxValue;;Now to convert it to Int32.int intVal = Convert.ToInt32(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       byte val = Byte.MaxValue;;       int intVal = Convert.ToInt32(val);       Console.WriteLine("Converted byte {0} to Int32 {1} value ", val, intVal);    } }OutputConverted byte 255 to Int32 255 value

Convert Double Value to Int64 in C#

karthikeya Boyini
Updated on 23-Jun-2020 08:47:13

2K+ Views

To convert a Double value to an Int64 value, use the Convert.ToInt64() method.Int64 represents a 64-bit signed integer.Let’s say the following is our double value.double val = 23.951213e12;Now to convert it to Int64.long longVal = Convert.ToInt64(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       double val = 23.951213e12;       long longVal = Convert.ToInt64(val);       Console.WriteLine("Converted double {0:E} to Int64 {1:N0} value ", val, longVal);    } }OutputConverted double 2.395121E+013 to Int64 23,951,213,000,000 value

Records Present in JavaScript Cookies

Daniol Thomas
Updated on 23-Jun-2020 08:46:46

208 Views

Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser sends the same cookie to the server for retrieval. Once retrieved, your server knows/remembers what was stored earlier.Cookies are a plain text data record of 5 variable-length fields −Expires − The date the cookie will expire. If this is blank, the cookie will expire when the visitor quits the browser.Domain − The ... Read More

C# Hash Any Method

Arjun Thakur
Updated on 23-Jun-2020 08:46:29

9K+ Views

The Any method checks whether any of the element in a sequence satisfy a specific condition or not.If any element satisfy the condition, true is returned.Let us see an example.int[] arr = {5, 7, 10, 12, 15, 18, 20};Now, using Any() method, we will check whether any of the element in the above array is greater than 10 or not.arr.AsQueryable().All(val => val > 5);If any of the element satisfies the condition, then True is returned.Let us see the complete example.Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = {5, 7, ... Read More

Convert Double to Integer in C#

Samual Sam
Updated on 23-Jun-2020 08:45:01

17K+ Views

To convert a Double value to an integer value, use the Convert.ToInt32() method.Int32 represents a 32-bit signed integer.Let’s say the following is our double value.double val = 21.34;Now to convert it to Int32.int res = Convert.ToInt32(val);Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       double val = 21.34;       int res = Convert.ToInt32(val);       Console.WriteLine("Converted double {0} to integer {1} ", val, res);    } }OutputConverted double 21.34 to integer 21

Implicit Conversion from Byte to Decimal in C#

Ankith Reddy
Updated on 23-Jun-2020 08:44:39

426 Views

Byte represents an 8-bit unsigned integer.Implicit conversion of an 8-bit unsigned integer (Byte) to a Decimal is possible. Let us see how.Here’s our Byte value.byte val = 16;To implicitly convert, just assign the value as shown below −decimal dec; dec = val;Let us see the complete example.Example Live Demousing System; public class Demo {    public static void Main() {       byte val = 16;       decimal dec;       // implicit       dec = val;       Console.WriteLine("Decimal ="+dec);    } }OutputDecimal =16

Implicit Conversion from 32-bit Unsigned Integer (uint) to Decimal in C#

karthikeya Boyini
Updated on 23-Jun-2020 08:44:10

827 Views

Implicit conversion of a 32-bit unsigned integer (UInt) to a Decimal requires you to first declare a UInt.uint val = 342741539;Now to convert it to decimal, just assign the value.decimal dec; // implicit dec = val;Example Live Demousing System; public class Demo {    public static void Main() {       uint val = 342741539;       decimal dec;       // implicit       dec = val;       Console.WriteLine("Decimal = "+dec);    } }OutputDecimal = 342741539

Advertisements