Understanding Chash OverflowException

karthikeya Boyini
Updated on 23-Jun-2020 08:56:02

993 Views

OverflowException is thrown when the parameter value is out of integer ranges.Let us see an example.When we set a value to int.Parse() method that is out of integer range, then OverflowException is thrown as shown below −Example Live Demousing System; class Demo {    static void Main() {       string str = "757657657657657";       int res = int.Parse(str);    } }OutputThe following error is thrown when the above program is compiled since we have passed a value that is out of integer (Int32) range.Unhandled Exception: System.OverflowException: Value was either too large or too small for an Int32.

C# Decimal D Format Specifier

George John
Updated on 23-Jun-2020 08:55:14

2K+ Views

The "D" (or decimal) format specifier works for integer type. It converts a number to a string of decimal digits (0-9).Let’say the following is our number.int val = 467;Now to return the result as 0467, use the following decimal format specifier.val.ToString("D4")Let us see another example.Example Live Demousing System; using System.Globalization; class Demo {    static void Main() {       int val;       val = 877;       Console.WriteLine(val.ToString("D"));       Console.WriteLine(val.ToString("D4"));       Console.WriteLine(val.ToString("D8"));    } }Output877 0877 00000877

Get Value of Usemap Attribute in JavaScript

Sharon Christine
Updated on 23-Jun-2020 08:53:15

318 Views

To get the value of the usemap attribute of a link in JavaScript, use the useMap property. The usemap attribute is used to tell that the document is html (text/html) or css (text/css), etc.Client-side image maps are enabled by the usemap attribute for the tag and defined by special and extension tags. The image that is going to form the map is inserted into the page using the element as normal, except that it carries an extra attribute called usemap.ExampleYou can try to run the following code to get the value of the usemap attribute of a link ... Read More

Match Regular Expression Against a String

Nancy Den
Updated on 23-Jun-2020 08:51:16

351 Views

Use the match() method to match a regular expression against a string in JavaScript. You can try to run the following code to match a regular expression −The following is the parameter −match( param ) − A regular expression object.ExampleYou can try to run the following code to match a regular expression against a string −           JavaScript String match() Method                        var str = "For more information, see Chapter 3.4.5.1";          var re = /(chapter \d+(\.\d)*)/i;          var found = str.match( re );                    document.write(found );          

Represent Int64 as a String in C#

Samual Sam
Updated on 23-Jun-2020 08:50:51

307 Views

Int64 represents a 64-bit signed integer. To represent it as a string, use the ToString() method.Firstly, declare and initialize an Int64 variable.long val = 8766776;Now, represent it as a string.val.ToString()Let us see the complete example.Example Live Demousing System; class Demo {    static void Main() {       long val = 8766776;       Console.Write("Long converted to string = "+val.ToString());    } }OutputLong converted to string = 8766776

Represent int64 as a Hexadecimal String in C#

Chandu yadav
Updated on 23-Jun-2020 08:50:32

2K+ Views

To represent Int64 as a Binary string in C#, use the ToString() method and set the base as the ToString() method’s second parameter i.e.16 for Hexadecimal.Int64 represents a 64-bit signed integer.Firstly, set an Int64 variable.long val = 947645;Now, convert it to a hex string by including 16 as the second parameter.Convert.ToString(val, 16)ExampleLive Demousing System; class Demo {    static void Main() {       long val = 947645;       Console.WriteLine("Long: "+val);       Console.Write("Hex String: "+Convert.ToString(val, 16));    } }OutputLong: 947645 Hex String: e75bd

The Hash Custom Specifier in C#

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

244 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

844 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

Advertisements