Int16.Parse(String) Method is used to convert the string representation of a number to its 16-bit signed integer equivalent.
public static short Parse (string str);
Here, str is a string that contains a number to convert. The format of str will be [optional white space][optional sign]digits[optional white space].
Return Value: It is a 16-bit signed integer equivalent to the number contained in str.
- ArgumentNullException: If str is null.
- FormatException: If str is not in the correct format.
- OverflowException: If str represents a number less than MinValue or greater than MaxValue.
Below programs illustrate the use of above-discussed method:
'14321' parsed as 14321 Can't Parsed '15,784' '-4589' parsed as -4589 ' 456' parsed as 456
Example 2: For ArgumentNullException
Exception Thrown: System.ArgumentNullException
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.