英語で読む

次の方法で共有


Int16.Parse メソッド

定義

数値の文字列形式を等価の 16 ビット符号付き整数に変換します。

オーバーロード

Parse(String, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャ固有の形式の数値の文字列形式を、等価の 16 ビット符号付き整数に変換します。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

指定したスタイルおよびカルチャ固有の形式の数値のスパン表現を、等価の 16 ビット符号付き整数に変換します。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

Parse(String, IFormatProvider)

指定したカルチャ固有の形式の数値の文字列形式を、等価の 16 ビット符号付き整数に変換します。

Parse(String)

数値の文字列形式を等価の 16 ビット符号付き整数に変換します。

Parse(ReadOnlySpan<Char>, IFormatProvider)

文字のスパンを値に解析します。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

UTF-8 文字のスパンを値に解析します。

Parse(String, NumberStyles)

指定したスタイルの数値の文字列形式を、等価の 16 ビット符号付き整数に変換します。

Parse(String, NumberStyles, IFormatProvider)

ソース:
Int16.cs
ソース:
Int16.cs
ソース:
Int16.cs

指定したスタイルおよびカルチャ固有の形式の数値の文字列形式を、等価の 16 ビット符号付き整数に変換します。

C#
public static short Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
C#
public static short Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);

パラメーター

s
String

変換する数値を含む文字列。

style
NumberStyles

sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供する IFormatProvider

戻り値

sで指定された数値に相当する 16 ビット符号付き整数。

実装

例外

snullです。

styleNumberStyles 値ではありません。

-又は-

style は、AllowHexSpecifier 値と HexNumber 値の組み合わせではありません。

s は、styleに準拠した形式ではありません。

は、Int16.MinValue より小さいか、Int16.MaxValueより大きい数値を表します。

-又は-

s には、0 以外の小数部の数字が含まれます。

次の例では、さまざまな style パラメーターと provider パラメーターを使用して、Int16 値の文字列表現を解析します。

C#
string value;
short number;
NumberStyles style;
CultureInfo provider;

// Parse string using "." as the thousands separator
// and " " as the decimal separator.
value = "19 694,00";
style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
provider = new CultureInfo("fr-FR");

number = Int16.Parse(value, style, provider);
Console.WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '19 694,00' converted to 19694.

try
{
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture);
   Console.WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '19 694,00'.

// Parse string using "$" as the currency symbol for en_GB and
// en-US cultures.
value = "$6,032.00";
style = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
provider = new CultureInfo("en-GB");

try
{
   number = Int16.Parse(value, style, CultureInfo.InvariantCulture);
   Console.WriteLine("'{0}' converted to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", value);
}
// Displays:
//    Unable to parse '$6,032.00'.

provider = new CultureInfo("en-US");
number = Int16.Parse(value, style, provider);
Console.WriteLine("'{0}' converted to {1}.", value, number);
// Displays:
//    '$6,032.00' converted to 6032.

注釈

style パラメーターは、解析操作を成功させるために s パラメーターで許可されるスタイル要素 (空白や正符号など) を定義します。 NumberStyles 列挙型のビット フラグの組み合わせである必要があります。 styleの値によっては、s パラメーターに次の要素が含まれる場合があります。

[ws][$][sign][digits,]digits[.fractional_digits][e[sign]digits][ws]

または、styleAllowHexSpecifierが含まれている場合:

[ws]hexdigits[ws]

角かっこ ([ と ]) の要素は省略可能です。 次の表では、各要素について説明します。

要素 形容
ws の 省略可能な空白。 styleNumberStyles.AllowLeadingWhite フラグが含まれている場合は s の先頭に空白が表示され、s の末尾に styleNumberStyles.AllowTrailingWhite フラグが含まれている場合は空白が表示されます。
$ カルチャ固有の通貨記号。 文字列内での位置は、現在のカルチャの NumberFormatInfo.CurrencyPositivePattern および NumberFormatInfo.CurrencyNegativePattern プロパティによって定義されます。 styleNumberStyles.AllowCurrencySymbol フラグが含まれている場合、現在のカルチャの通貨記号は s に表示されます。
sign 省略可能な記号。 styleNumberStyles.AllowLeadingSign フラグが含まれている場合は s の先頭に表示され、NumberStyles.AllowTrailingSign フラグ style 含まれている場合は s の末尾に表示されます。 s でかっこを使用すると、styleNumberStyles.AllowParentheses フラグが含まれている場合に負の値を示すことができます。
桁の 0 から 9 までの数字のシーケンス。
カルチャ固有の桁区切り記号。 現在のカルチャの桁区切り記号は、NumberStyles.AllowThousands フラグ style 含まれている場合、s に表示されます。
. カルチャ固有の小数点記号。 styleNumberStyles.AllowDecimalPoint フラグが含まれている場合、現在のカルチャの小数点記号は s に表示されます。
fractional_digits 0 桁のシーケンス。 styleNumberStyles.AllowDecimalPoint フラグが含まれている場合、小数部の数字は s に表示されます。 fractional_digitsに 0 以外の数字が表示された場合、メソッドは OverflowExceptionをスローします。
e 'e' または 'E' 文字。これは、s を指数表記で表すことができることを示します。 s パラメーターは、NumberStyles.AllowExponent フラグが含まれている場合 style 指数表記で数値を表すことができます。 ただし、s パラメーターは、Int16 データ型の範囲内の数値を表す必要があり、0 以外の小数部を持つことはできません。
hexdigits を する 0 から f、または 0 から F までの 16 進数のシーケンス。

注意

s で終了する NUL (U+0000) 文字は、style 引数の値に関係なく、解析操作では無視されます。

桁の文字列 のみ (NumberStyles.None スタイルに対応) は常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、この入力文字列に存在する必要がない要素を制御します。 次の表は、個々の NumberStyles メンバーが、sに存在する可能性がある要素に与える影響を示しています。

非複合 NumberStyles 値 数字に加えて s で許可される要素
NumberStyles.None 10 進数のみ。
NumberStyles.AllowDecimalPoint . 要素と fractional_digits 要素。 ただし、fractional_digits は 1 つ以上の 0 桁のみで構成する必要があります。または、OverflowException がスローされます。
NumberStyles.AllowExponent s パラメーターでは指数表記を使用することもできます。
NumberStyles.AllowLeadingWhite sの先頭にある ws 要素。
NumberStyles.AllowTrailingWhite sの末尾にある ws 要素。
NumberStyles.AllowLeadingSign 数字の前に記号表示できます。
NumberStyles.AllowTrailingSign 数字の後に記号が表示される場合があります。
NumberStyles.AllowParentheses 符号、数値を囲むかっこの形式で要素に署名します。
NumberStyles.AllowThousands 要素。
NumberStyles.AllowCurrencySymbol $ 要素。

NumberStyles.AllowHexSpecifier フラグを使用する場合、s はプレフィックスのない 16 進値の文字列表現である必要があります。 たとえば、"9AF3" は正常に解析されますが、"0x9AF3" は解析されません。 style に存在できる他のフラグは、NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteだけです。 (NumberStyles 列挙には、両方の空白フラグを含む複合数値スタイル (NumberStyles.HexNumber) があります。

provider パラメーターは、GetFormat メソッドが NumberFormatInfo オブジェクトを取得する IFormatProvider 実装です。 NumberFormatInfo オブジェクトは、sの形式に関するカルチャ固有の情報を提供します。 providernullされている場合は、現在のカルチャの NumberFormatInfo オブジェクトが使用されます。

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

ソース:
Int16.cs
ソース:
Int16.cs
ソース:
Int16.cs

指定したスタイルおよびカルチャ固有の形式の数値のスパン表現を、等価の 16 ビット符号付き整数に変換します。

C#
public static short Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
C#
public static short Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);

パラメーター

s
ReadOnlySpan<Char>

変換する数値を表す文字を含むスパン。

style
NumberStyles

sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供する IFormatProvider

戻り値

sで指定された数値に相当する 16 ビット符号付き整数。

実装

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Standard 2.1

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

ソース:
Int16.cs
ソース:
Int16.cs

UTF-8 文字のスパンを値に解析します。

C#
public static short Parse (ReadOnlySpan<byte> utf8Text, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

style
NumberStyles

utf8Textに存在できる数値スタイルのビットごとの組み合わせ。

provider
IFormatProvider

utf8Textに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

utf8Text解析の結果。

実装

適用対象

.NET 9 および .NET 8
製品 バージョン
.NET 8, 9

Parse(String, IFormatProvider)

ソース:
Int16.cs
ソース:
Int16.cs
ソース:
Int16.cs

指定したカルチャ固有の形式の数値の文字列形式を、等価の 16 ビット符号付き整数に変換します。

C#
public static short Parse (string s, IFormatProvider provider);
C#
public static short Parse (string s, IFormatProvider? provider);

パラメーター

s
String

変換する数値を含む文字列。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供する IFormatProvider

戻り値

sで指定された数値に相当する 16 ビット符号付き整数。

実装

例外

snullです。

s が正しい形式ではありません。

は、Int16.MinValue より小さいか、Int16.MaxValueより大きい数値を表します。

次の例では、Int16.Parse(String, IFormatProvider) メソッドを使用して Int16 値の文字列表現を解析します。

C#
string stringToConvert;
short number;

stringToConvert = " 214 ";
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.",
                     stringToConvert);
}

stringToConvert = " + 214";
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.",
                     stringToConvert);
}

stringToConvert = " +214 ";
try
{
   number = Int16.Parse(stringToConvert, CultureInfo.InvariantCulture);
   Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse '{0}'.", stringToConvert);
}
catch (OverflowException)
{
   Console.WriteLine("'{0'} is out of range of the Int16 data type.",
                     stringToConvert);
}
// The example displays the following output to the console:
//       Converted ' 214 ' to 214.
//       Unable to parse ' + 214'.
//       Converted ' +214 ' to 214.

注釈

s パラメーターには、次の形式が含まれています。

[ws][sign]digits[ws]

角かっこ ([ と ]) の要素は省略可能です。 次の表では、各要素について説明します。

要素 形容
ws 省略可能な空白。
看板 省略可能な記号。
0 から 9 までの数字のシーケンス。

s パラメーターは、NumberStyles.Integer スタイルを使用して解釈されます。 sでは、10 進数に加えて、先頭と末尾のスペースと先頭の符号のみを使用できます。 sに存在できるカルチャ固有の書式設定情報と共にスタイル要素を明示的に定義するには、Int16.Parse(String, NumberStyles, IFormatProvider) メソッドを使用します。

provider パラメーターは、NumberFormatInfo オブジェクトを取得する IFormatProvider 実装です。 NumberFormatInfo は、sの形式に関するカルチャ固有の情報を提供します。 providernullされている場合は、現在のカルチャの NumberFormatInfo が使用されます。

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Parse(String)

ソース:
Int16.cs
ソース:
Int16.cs
ソース:
Int16.cs

数値の文字列形式を等価の 16 ビット符号付き整数に変換します。

C#
public static short Parse (string s);

パラメーター

s
String

変換する数値を含む文字列。

戻り値

sに含まれる数値に相当する 16 ビット符号付き整数。

例外

snullです。

s が正しい形式ではありません。

は、Int16.MinValue より小さいか、Int16.MaxValueより大きい数値を表します。

次の例では、Int16.Parse(String) メソッドを使用して、文字列値を 16 ビット符号付き整数値に変換する方法を示します。 結果の整数値がコンソールに表示されます。

C#
string value;
short number;

value = " 12603 ";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.",
                     value);
}

value = " 16,054";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.",
                     value);
}

value = " -17264";
try
{
   number = Int16.Parse(value);
   Console.WriteLine("Converted '{0}' to {1}.", value, number);
}
catch (FormatException)
{
   Console.WriteLine("Unable to convert '{0}' to a 16-bit signed integer.",
                     value);
}
// The example displays the following output to the console:
//       Converted ' 12603 ' to 12603.
//       Unable to convert ' 16,054' to a 16-bit signed integer.
//       Converted ' -17264' to -17264.

注釈

s パラメーターには、次の形式が含まれています。

[ws][sign]digits[ws]

角かっこ ([ と ]) の要素は省略可能です。 次の表では、各要素について説明します。

要素 形容
ws の 省略可能な空白。
sign 省略可能な記号。
桁の 0 から 9 までの数字のシーケンス。

s パラメーターは、NumberStyles.Integer スタイルを使用して解釈されます。 整数値の 10 進数に加えて、先頭と末尾のスペースと先頭の符号のみを使用できます。 sに存在できるスタイル要素を明示的に定義するには、Int16.Parse(String, NumberStyles) メソッドまたは Parse メソッドを使用します。

s パラメーターは、現在のシステム カルチャ用に初期化された NumberFormatInfo オブジェクトの書式設定情報を使用して解析されます。 詳細については、CurrentInfoを参照してください。 他のカルチャの書式設定情報を使用して文字列を解析するには、Int16.Parse(String, IFormatProvider) または Int16.Parse(String, NumberStyles, IFormatProvider) メソッドを使用します。

こちらもご覧ください

  • ToString()
  • .NET での数値文字列の解析の

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Parse(ReadOnlySpan<Char>, IFormatProvider)

ソース:
Int16.cs
ソース:
Int16.cs
ソース:
Int16.cs

文字のスパンを値に解析します。

C#
public static short Parse (ReadOnlySpan<char> s, IFormatProvider? provider);

パラメーター

s
ReadOnlySpan<Char>

解析する文字のスパン。

provider
IFormatProvider

sに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

s解析の結果。

実装

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 7, 8, 9

Parse(ReadOnlySpan<Byte>, IFormatProvider)

ソース:
Int16.cs
ソース:
Int16.cs

UTF-8 文字のスパンを値に解析します。

C#
public static short Parse (ReadOnlySpan<byte> utf8Text, IFormatProvider? provider);

パラメーター

utf8Text
ReadOnlySpan<Byte>

解析する UTF-8 文字のスパン。

provider
IFormatProvider

utf8Textに関するカルチャ固有の書式設定情報を提供するオブジェクト。

戻り値

utf8Text解析の結果。

実装

適用対象

.NET 9 および .NET 8
製品 バージョン
.NET 8, 9

Parse(String, NumberStyles)

ソース:
Int16.cs
ソース:
Int16.cs
ソース:
Int16.cs

指定したスタイルの数値の文字列形式を、等価の 16 ビット符号付き整数に変換します。

C#
public static short Parse (string s, System.Globalization.NumberStyles style);

パラメーター

s
String

変換する数値を含む文字列。

style
NumberStyles

sに存在できるスタイル要素を示す列挙値のビットごとの組み合わせ。 指定する一般的な値は Integerです。

戻り値

sで指定された数値に相当する 16 ビット符号付き整数。

例外

snullです。

styleNumberStyles 値ではありません。

-又は-

style は、AllowHexSpecifier 値と HexNumber 値の組み合わせではありません。

s は、styleに準拠した形式ではありません。

は、Int16.MinValue より小さいか、Int16.MaxValueより大きい数値を表します。

-又は-

s には、0 以外の小数部の数字が含まれます。

次の例では、Int16.Parse(String, NumberStyles) メソッドを使用して、en-US カルチャを使用して Int16 値の文字列形式を解析します。

C#
using System;
using System.Globalization;

public class ParseSample
{
   public static void Main()
   {
      string value;
      NumberStyles style;

      // Parse a number with a thousands separator (throws an exception).
      value = "14,644";
      style = NumberStyles.None;
      ParseToInt16(value, style);

      style = NumberStyles.AllowThousands;
      ParseToInt16(value, style);

      // Parse a number with a thousands separator and decimal point.
      value = "14,644.00";
      style = NumberStyles.AllowThousands | NumberStyles.Integer |
              NumberStyles.AllowDecimalPoint;
      ParseToInt16(value, style);

      // Parse a number with a fractional component (throws an exception).
      value = "14,644.001";
      ParseToInt16(value, style);

      // Parse a number in exponential notation.
      value = "145E02";
      style = style | NumberStyles.AllowExponent;
      ParseToInt16(value, style);

      // Parse a number in exponential notation with a positive sign.
      value = "145E+02";
      ParseToInt16(value, style);

      // Parse a number in exponential notation with a negative sign
      // (throws an exception).
      value = "145E-02";
      ParseToInt16(value, style);
   }

   private static void ParseToInt16(string value, NumberStyles style)
   {
      try
      {
         short number = Int16.Parse(value, style);
         Console.WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException)
      {
         Console.WriteLine("Unable to parse '{0}' with style {1}.", value,
                           style.ToString());
      }
      catch (OverflowException)
      {
         Console.WriteLine("'{0}' is out of range of the Int16 type.", value);
      }
   }
}
// The example displays the following output to the console:
//       Unable to parse '14,644' with style None.
//       Converted '14,644' to 14644.
//       Converted '14,644.00' to 14644.
//       '14,644.001' is out of range of the Int16 type.
//       Converted '145E02' to 14500.
//       Converted '145E+02' to 14500.
//       '145E-02' is out of range of the Int16 type.

注釈

style パラメーターは、解析操作を成功させるために s パラメーターで許可されるスタイル要素 (空白や記号など) を定義します。 NumberStyles 列挙型のビット フラグの組み合わせである必要があります。 styleの値によっては、s パラメーターに次の要素が含まれる場合があります。

[ws][$][sign][digits,]digits[.fractional_digits][e[sign]digits][ws]

または、styleAllowHexSpecifierが含まれている場合:

[ws]hexdigits[ws]

角かっこ ([ と ]) の項目は省略可能です。 次の表では、各要素について説明します。

要素 形容
ws の 省略可能な空白。 styleNumberStyles.AllowLeadingWhite フラグが含まれている場合は s の先頭に空白が表示され、s の末尾に styleNumberStyles.AllowTrailingWhite フラグが含まれている場合は空白が表示されます。
$ カルチャ固有の通貨記号。 文字列内での位置は、現在のカルチャの NumberFormatInfo.CurrencyPositivePattern および NumberFormatInfo.CurrencyNegativePattern プロパティによって定義されます。 styleNumberStyles.AllowCurrencySymbol フラグが含まれている場合、現在のカルチャの通貨記号は s に表示されます。
sign 省略可能な記号。 styleNumberStyles.AllowLeadingSign フラグが含まれている場合は s の先頭に表示され、NumberStyles.AllowTrailingSign フラグ style 含まれている場合は s の末尾に表示されます。 s でかっこを使用すると、styleNumberStyles.AllowParentheses フラグが含まれている場合に負の値を示すことができます。
桁の 0 から 9 までの数字のシーケンス。
カルチャ固有の桁区切り記号。 現在のカルチャの桁区切り記号は、NumberStyles.AllowThousands フラグ style 含まれている場合、s に表示されます。
. カルチャ固有の小数点記号。 styleNumberStyles.AllowDecimalPoint フラグが含まれている場合、現在のカルチャの小数点記号は s に表示されます。
fractional_digits 0 桁のシーケンス。 styleNumberStyles.AllowDecimalPoint フラグが含まれている場合、小数部の数字は s に表示されます。 fractional_digitsに 0 以外の数字が表示された場合、メソッドは OverflowExceptionをスローします。
e 'e' または 'E' 文字。これは、s を指数表記で表すことができることを示します。 s パラメーターは、NumberStyles.AllowExponent フラグが含まれている場合 style 指数表記で数値を表すことができます。 ただし、s パラメーターは、Int16 データ型の範囲内の数値を表す必要があり、0 以外の小数部を持つことはできません。
hexdigits を する 0 から f、または 0 から F までの 16 進数のシーケンス。

注意

s で終了する NUL (U+0000) 文字は、style 引数の値に関係なく、解析操作では無視されます。

桁の文字列 のみ (NumberStyles.None スタイルに対応) は常に正常に解析されます。 残りの NumberStyles メンバーのほとんどは、この入力文字列に存在する必要がない要素を制御します。 次の表は、個々の NumberStyles メンバーが、sに存在する可能性がある要素に与える影響を示しています。

非複合 NumberStyles 値 数字に加えて s で許可される要素
NumberStyles.None 10 進数のみ。
NumberStyles.AllowDecimalPoint . 要素と fractional_digits 要素。 ただし、fractional_digits は 1 つ以上の 0 桁のみで構成する必要があります。または、OverflowException がスローされます。
NumberStyles.AllowExponent s パラメーターでは指数表記を使用することもできます。
NumberStyles.AllowLeadingWhite sの先頭にある ws 要素。
NumberStyles.AllowTrailingWhite sの末尾にある ws 要素。
NumberStyles.AllowLeadingSign 数字の前に記号表示できます。
NumberStyles.AllowTrailingSign 数字の後に記号が表示される場合があります。
NumberStyles.AllowParentheses 符号、数値を囲むかっこの形式で要素に署名します。
NumberStyles.AllowThousands 要素。
NumberStyles.AllowCurrencySymbol $ 要素。

NumberStyles.AllowHexSpecifier フラグを使用する場合、s はプレフィックスのない 16 進値の文字列表現である必要があります。 たとえば、"9AF3" は正常に解析されますが、"0x9AF3" では解析されません。 style に存在できる他のフラグは、NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteだけです。 (NumberStyles 列挙には、両方の空白フラグを含む複合数値スタイル (NumberStyles.HexNumber) があります。

s パラメーターは、現在のシステム カルチャ用に初期化された NumberFormatInfo オブジェクトの書式設定情報を使用して解析されます。 詳細については、NumberFormatInfo.CurrentInfoを参照してください。 特定のカルチャの書式設定情報を使用して s を解析するには、Int16.Parse(String, NumberStyles, IFormatProvider) メソッドを呼び出します。

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0