Mono Class Library: System.Int16 Overview | Members

System.Int16.Parse Method

Returns the specified string converted to a short value.

public static short Parse (string s)

Parameters

s
A string containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Integer style.

Returns

The short value obtained from s.

Exceptions

TypeReason
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than short.MaxValue or less than short.MinValue.

Remarks

This version of short.Parse(string) is equivalent to short.Parse(string) (s, System.Globalization.NumberStyles.Integer, null ).

The string s is parsed using the formatting information in a System.Globalization.NumberFormatInfo initialized for the current system culture.

Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo.

Example

This example demonstrates parsing a string to a short.

C# Example

using System;
public class Int16ParseClass {
  public static void Main() {
    string str = "  100   ";
    Console.WriteLine("String: \"{0}\" <Int16> {1}",str,Int16.Parse(str));
  }
}

The output is

String: " 100 " <Int16> 100

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0