Int64.Parse 方法

定义

将数字的字符串表示形式转换为其等效的 64 位带符号整数。

重载

Parse(String)

将数字的字符串表示形式转换为其等效的 64 位带符号整数。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

将 UTF-8 字符的范围分析为值。

Parse(ReadOnlySpan<Char>, IFormatProvider)

将字符的范围分析为值。

Parse(String, NumberStyles)

将指定样式中的数字的字符串表示形式转换为其等效的 64 位带符号整数。

Parse(String, IFormatProvider)

将指定区域性特定格式的数字的字符串表示形式转换为其等效的 64 位带符号整数。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

将 UTF-8 字符的范围分析为值。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的跨度表示形式转换为其等效的 64 位带符号整数。

Parse(String, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的字符串表示形式转换为其等效的 64 位带符号整数。

Parse(String)

Source:
Int64.cs
Source:
Int64.cs
Source:
Int64.cs

将数字的字符串表示形式转换为其等效的 64 位带符号整数。

C#
public static long Parse (string s);

参数

s
String

包含要转换的数字的字符串。

返回

s中包含的数字等效的 64 位有符号整数。

例外

s 格式不正确。

s 表示小于 Int64.MinValue 或大于 Int64.MaxValue的数字。

示例

以下示例演示如何使用 Int64.Parse(String) 方法将字符串值转换为 64 位有符号整数值。 然后,它显示生成的长整数值。

C#
using System;

public class ParseInt64
{
   public static void Main()
   {
      Convert("  179042  ");
      Convert(" -2041326 ");
      Convert(" +8091522 ");
      Convert("   1064.0   ");
      Convert("  178.3");
      Convert(String.Empty);
      Convert(((decimal) Int64.MaxValue) + 1.ToString());
   }

   private static void Convert(string value)
   {
      try
      {
         long number = Int64.Parse(value);
         Console.WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException)
      {
         Console.WriteLine("Unable to convert '{0}'.", value);
      }
      catch (OverflowException)
      {
         Console.WriteLine("'{0}' is out of range.", value);
      }
   }
}
// This example displays the following output to the console:
//       Converted '  179042  ' to 179042.
//       Converted ' -2041326 ' to -2041326.
//       Converted ' +8091522 ' to 8091522.
//       Unable to convert '   1064.0   '.
//       Unable to convert '  178.3'.
//       Unable to convert ''.
//       '92233720368547758071' is out of range.

注解

s 参数包含多种形式:

[ws][sign]digits[ws]

方括号 ([ 和 ]) 中的元素是可选的。 下表描述了每个元素。

元素 描述
ws 可选空格。
标志 可选符号。
数字 一系列数字,范围从 0 到 9。

s 参数使用 NumberStyles.Integer 样式进行解释。 除了十进制数字,还允许使用前导符号和尾随空格。 若要显式定义 s中可以存在的样式元素,请使用 Int64.Parse(String, NumberStyles)Int64.Parse(String, NumberStyles, IFormatProvider) 方法。

s 参数是使用为当前系统区域性初始化的 NumberFormatInfo 对象中的格式信息进行分析的。 若要使用其他区域性的格式设置信息分析字符串,请使用 Int64.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

Parse(ReadOnlySpan<Byte>, IFormatProvider)

Source:
Int64.cs
Source:
Int64.cs

将 UTF-8 字符的范围分析为值。

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

参数

utf8Text
ReadOnlySpan<Byte>

要分析的 UTF-8 字符的范围。

provider
IFormatProvider

一个对象,提供有关 utf8Text的区域性特定格式设置信息。

返回

分析 utf8Text的结果。

实现

适用于

.NET 9 和 .NET 8
产品 版本
.NET 8, 9

Parse(ReadOnlySpan<Char>, IFormatProvider)

Source:
Int64.cs
Source:
Int64.cs
Source:
Int64.cs

将字符的范围分析为值。

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

参数

s
ReadOnlySpan<Char>

要分析的字符范围。

provider
IFormatProvider

一个对象,提供有关 s的区域性特定格式设置信息。

返回

分析 s的结果。

实现

适用于

.NET 9 和其他版本
产品 版本
.NET 7, 8, 9

Parse(String, NumberStyles)

Source:
Int64.cs
Source:
Int64.cs
Source:
Int64.cs

将指定样式中的数字的字符串表示形式转换为其等效的 64 位带符号整数。

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

参数

s
String

包含要转换的数字的字符串。

style
NumberStyles

指示允许 s格式的 NumberStyles 值的按位组合。 要指定的典型值为 Integer

返回

s中指定的数字等效的 64 位有符号整数。

例外

style 不是 NumberStyles 值。

-或-

style 不是 AllowHexSpecifierHexNumber 值的组合。

s 的格式不符合 style

s 表示小于 Int64.MinValue 或大于 Int64.MaxValue的数字。

-或-

style 支持小数位数,但 s 包括非零的小数位数。

示例

以下示例使用 Int64.Parse(String, NumberStyles) 方法分析多个 Int64 值的字符串表示形式。 本示例的当前区域性为 en-US。

C#
using System;
using System.Globalization;

public class ParseInt32
{
   public static void Main()
   {
      Convert("104.0", NumberStyles.AllowDecimalPoint);
      Convert("104.9", NumberStyles.AllowDecimalPoint);
      Convert (" 106034", NumberStyles.None);
      Convert(" $17,198,064.42", NumberStyles.AllowCurrencySymbol |
                                 NumberStyles.Number);
      Convert(" $17,198,064.00", NumberStyles.AllowCurrencySymbol |
                                 NumberStyles.Number);
      Convert("103E06", NumberStyles.AllowExponent);
      Convert("1200E-02", NumberStyles.AllowExponent);
      Convert("1200E-03", NumberStyles.AllowExponent);
      Convert("-1,345,791", NumberStyles.AllowThousands);
      Convert("(1,345,791)", NumberStyles.AllowThousands |
                             NumberStyles.AllowParentheses);
      Convert("FFCA00A0", NumberStyles.HexNumber);
      Convert("0xFFCA00A0", NumberStyles.HexNumber);
   }

   private static void Convert(string value, NumberStyles style)
   {
      try
      {
         long number = Int64.Parse(value, style);
         Console.WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException)
      {
         Console.WriteLine("Unable to convert '{0}'.", value);
      }
      catch (OverflowException)
      {
         Console.WriteLine("'{0}' is out of range of the Int64 type.", value);
      }
   }
}
// The example displays the following output to the console:
//       Converted '104.0' to 104.
//       '104.9' is out of range of the Int64 type.
//       Unable to convert ' 106034'.
//       ' $17,198,064.42' is out of range of the Int64 type.
//       Converted ' $17,198,064.00' to 17198064.
//       Converted '103E06' to 103000000.
//       Converted '1200E-02' to 12.
//       '1200E-03' is out of range of the Int64 type.
//       Unable to convert '-1,345,791'.
//       Converted '(1,345,791)' to -1345791.
//       Converted 'FFCA00A0' to 4291428512.
//       Unable to convert '0xFFCA00A0'.

注解

style 参数定义允许在 s 参数中成功执行分析操作的样式元素(如空格、正符号或负号符号或千位分隔符符号)。 它必须是 NumberStyles 枚举中的位标志的组合。 根据 style的值,s 参数可能包含以下元素:

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

或者,如果 style 包括 AllowHexSpecifier

[ws]hexdigits[ws]

方括号 ([ 和 ]) 中的元素是可选的。 下表描述了每个元素。

元素 描述
ws 可选空格。 如果 style 包含 NumberStyles.AllowLeadingWhite 标志,则空格可能出现在 s 的开头,如果 style 包含 NumberStyles.AllowTrailingWhite 标志,则它将显示在 s 末尾。
$ 区域性特定的货币符号。 字符串中的位置由当前区域性的 NumberFormatInfo.CurrencyNegativePatternNumberFormatInfo.CurrencyPositivePattern 属性定义。 如果 style 包含 NumberStyles.AllowCurrencySymbol 标志,则当前区域性的货币符号可以出现在 s 中。
签名 可选符号。 如果 style 包含 NumberStyles.AllowLeadingSign 标志,则符号可以在 s 开头显示,如果 style 包含 NumberStyles.AllowTrailingSign 标志,则它将显示在 s 末尾。 如果 style 包含 NumberStyles.AllowParentheses 标志,则可以在 s 中使用括号来指示负值。


fractional_digits

exponential_digits
从 0 到 9 的数字序列。 对于 fractional_digits,只有数字 0 有效。
区域性特定的千位分隔符符号。 如果 style 包含 NumberStyles.AllowThousands 标志,则当前区域性的千位分隔符可以出现在 s 中。
区域性特定的小数点符号。 如果 style 包含 NumberStyles.AllowDecimalPoint 标志,则当前区域性的小数点符号可以出现在 s 中。 只有数字 0 可以显示为分析操作成功的小数位数;如果 fractional_digits 包含任何其他数字,则会引发 OverflowException
e “e”或“E”字符,指示该值以指数表示法表示。 如果 style 包含 NumberStyles.AllowExponent 标志,s 参数可以表示指数表示法中的数字。
hexdigits 从 0 到 f 或 0 到 F 的十六进制数字序列。

备注

无论 style 参数的值如何,分析操作都会忽略 s 中任何终止的 NUL (U+0000) 字符。

仅包含数字(对应于 NumberStyles.None 样式)的字符串在 Int64 类型范围内时始终成功分析。 其余大多数 NumberStyles 成员控制可能但不需要在输入字符串中存在的元素。 下表指示单个 NumberStyles 成员如何影响 s中可能存在的元素。

NumberStyles 值 除数字外允许的元素
None 仅 元素 位数。
AllowDecimalPoint 小数点(.)和 小数位数 元素。
AllowExponent s 参数也可以使用指数表示法。 如果 s 以指数表示法表示数字,则生成的数值不能包含任何非零的小数位数。
AllowLeadingWhite s开头的 ws 元素。
AllowTrailingWhite s末尾的 ws 元素。
AllowLeadingSign s开头的 符号 元素。
AllowTrailingSign s末尾的 符号 元素。
AllowParentheses 符号 元素,以括住数值的括号形式。
AllowThousands 千位分隔符()元素。
AllowCurrencySymbol $ 元素。
Currency 都。 s 参数不能表示十六进制数或指数表示法中的数字。
Float ws 元素位于 s的开头或末尾,符号s开头,以及小数点(.)符号。 s 参数也可以使用指数表示法。
Number ws符号、千位分隔符()和小数点(.)元素。
Any s 之外的所有样式都不能表示十六进制数。

如果使用 NumberStyles.AllowHexSpecifier 标志,s 必须是没有前缀的十六进制值。 例如,“C9AF3”已成功分析,但“0xC9AF3”不会。 唯一可与 s 参数组合的其他标志是 NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhite。 (NumberStyles 枚举包括包含两个空格标志的复合数字样式 NumberStyles.HexNumber

s 参数是使用为当前系统区域性初始化的 NumberFormatInfo 对象中的格式信息进行分析的。 若要指定其格式设置信息用于分析操作的区域性,请调用 Int64.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

Parse(String, IFormatProvider)

Source:
Int64.cs
Source:
Int64.cs
Source:
Int64.cs

将指定区域性特定格式的数字的字符串表示形式转换为其等效的 64 位带符号整数。

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

参数

s
String

包含要转换的数字的字符串。

provider
IFormatProvider

一个对象,提供有关 s的区域性特定格式设置信息。

返回

s中指定的数字等效的 64 位有符号整数。

实现

例外

s 格式不正确。

s 表示小于 Int64.MinValue 或大于 Int64.MaxValue的数字。

示例

以下示例是 Web 窗体的按钮单击事件处理程序。 它使用 HttpRequest.UserLanguages 属性返回的数组来确定用户的区域设置。 然后,它会实例化与该区域设置对应的 CultureInfo 对象。 然后,将属于该 CultureInfo 对象的 NumberFormatInfo 对象传递给 Parse(String, IFormatProvider) 方法,将用户的输入转换为 Int64 值。

C#
protected void OkToLong_Click(object sender, EventArgs e)
{
    string locale;
    long number;
    CultureInfo culture;

    // Return if string is empty
    if (String.IsNullOrEmpty(this.inputNumber.Text))
        return;

    // Get locale of web request to determine possible format of number
    if (Request.UserLanguages.Length == 0)
        return;
    locale = Request.UserLanguages[0];
    if (String.IsNullOrEmpty(locale))
        return;

    // Instantiate CultureInfo object for the user's locale
    culture = new CultureInfo(locale);

    // Convert user input from a string to a number
    try
    {
        number = Int64.Parse(this.inputNumber.Text, culture.NumberFormat);
    }
    catch (FormatException)
    {
        return;
    }
    catch (Exception)
    {
        return;
    }
    // Output number to label on web form
    this.outputNumber.Text = "Number is " + number.ToString();
}

注解

Parse(String, IFormatProvider) 方法的此重载通常用于将可通过多种方式格式化的文本转换为 Int64 值。 例如,它可用于将用户输入的文本转换为 HTML 文本框,并将其转换为数值。

s 参数包含多种形式:

[ws][sign]digits[ws]

方括号 ([ 和 ]) 中的项是可选的,其他项如下所示。

ws 可选空格。

为可选符号签名。

digits A sequence of digits from 0 to 9.

s 参数使用 NumberStyles.Integer 样式进行解释。 除了十进制数字,还允许使用前导符号和尾随空格。 若要显式定义可在 s中存在的样式元素,请使用 Int64.Parse(String, NumberStyles, IFormatProvider) 方法。

provider 参数是 IFormatProvider 实现,例如 NumberFormatInfoCultureInfo 对象。 provider 参数提供有关 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<Byte>, NumberStyles, IFormatProvider)

Source:
Int64.cs
Source:
Int64.cs

将 UTF-8 字符的范围分析为值。

C#
public static long 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(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

Source:
Int64.cs
Source:
Int64.cs
Source:
Int64.cs

将指定样式和区域性特定格式的数字的跨度表示形式转换为其等效的 64 位带符号整数。

C#
public static long Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
C#
public static long 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中指定的数字等效的 64 位有符号整数。

实现

适用于

.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(String, NumberStyles, IFormatProvider)

Source:
Int64.cs
Source:
Int64.cs
Source:
Int64.cs

将指定样式和区域性特定格式的数字的字符串表示形式转换为其等效的 64 位带符号整数。

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

参数

s
String

包含要转换的数字的字符串。

style
NumberStyles

枚举值的按位组合,指示 s中可以存在的样式元素。 要指定的典型值为 Integer

provider
IFormatProvider

提供有关 s的区域性特定格式设置信息的 IFormatProvider

返回

s中指定的数字等效的 64 位有符号整数。

实现

例外

style 不是 NumberStyles 值。

-或-

style 不是 AllowHexSpecifierHexNumber 值的组合。

s 的格式不符合 style

s 表示小于 Int64.MinValue 或大于 Int64.MaxValue的数字。

-或-

style 支持小数位数,但 s 包括非零的小数位数。

示例

以下示例使用各种 styleprovider 参数分析 Int64 值的字符串表示形式。 它还演示了一些不同的方法,可以根据格式设置信息用于分析操作的区域性来解释同一字符串。

C#
using System;
using System.Globalization;

public class ParseInt64
{
   public static void Main()
   {
      Convert("12,000", NumberStyles.Float | NumberStyles.AllowThousands,
              new CultureInfo("en-GB"));
      Convert("12,000", NumberStyles.Float | NumberStyles.AllowThousands,
              new CultureInfo("fr-FR"));
      Convert("12,000", NumberStyles.Float, new CultureInfo("en-US"));

      Convert("12 425,00", NumberStyles.Float | NumberStyles.AllowThousands,
              new CultureInfo("sv-SE"));
      Convert("12,425.00", NumberStyles.Float | NumberStyles.AllowThousands,
              NumberFormatInfo.InvariantInfo);
      Convert("631,900", NumberStyles.Integer | NumberStyles.AllowDecimalPoint,
              new CultureInfo("fr-FR"));
      Convert("631,900", NumberStyles.Integer | NumberStyles.AllowDecimalPoint,
              new CultureInfo("en-US"));
      Convert("631,900", NumberStyles.Integer | NumberStyles.AllowThousands,
              new CultureInfo("en-US"));
   }

   private static void Convert(string value, NumberStyles style,
                               IFormatProvider provider)
   {
      try
      {
         long number = Int64.Parse(value, style, provider);
         Console.WriteLine("Converted '{0}' to {1}.", value, number);
      }
      catch (FormatException)
      {
         Console.WriteLine("Unable to convert '{0}'.", value);
      }
      catch (OverflowException)
      {
         Console.WriteLine("'{0}' is out of range of the Int64 type.", value);
      }
   }
}
// This example displays the following output to the console:
//       Converted '12,000' to 12000.
//       Converted '12,000' to 12.
//       Unable to convert '12,000'.
//       Converted '12 425,00' to 12425.
//       Converted '12,425.00' to 12425.
//       '631,900' is out of range of the Int64 type.
//       Unable to convert '631,900'.
//       Converted '631,900' to 631900.

注解

style 参数定义 s 参数中允许的样式元素(如空格或正号),以便分析操作成功。 它必须是 NumberStyles 枚举中的位标志的组合。 根据 style的值,s 参数可能包括以下元素:

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

或者,如果 style 包括 AllowHexSpecifier

[ws]hexdigits[ws]

方括号 ([ 和 ]) 中的元素是可选的。 下表描述了每个元素。

元素 描述
ws 可选空格。 如果 style 包含 NumberStyles.AllowLeadingWhite 标志,则空格可能出现在 s 的开头,如果 style 包含 NumberStyles.AllowTrailingWhite 标志,则它将显示在 s 末尾。
$ 区域性特定的货币符号。 字符串中的位置由 provider 参数的 GetFormat 方法返回的 NumberFormatInfo 对象的 NumberFormatInfo.CurrencyPositivePattern 属性定义。 如果 style 包含 NumberStyles.AllowCurrencySymbol 标志,货币符号可以出现在 s 中。
签名 可选符号。 如果 style 包含 NumberStyles.AllowLeadingSign 标志或 s 末尾(如果 style 包含 NumberStyles.AllowTrailingSign 标志,则符号可能显示在 s 的开头。 如果 style 包含 NumberStyles.AllowParentheses 标志,则可以在 s 中使用括号来指示负值。


fractional_digits

exponential_digits
从 0 到 9 的数字序列。
区域性特定的千位分隔符符号。 如果 style 包含 NumberStyles.AllowThousands 标志,则由 provider 指定的区域性的千位分隔符可以出现在 s 中。
区域性特定的小数点符号。 如果 style 包含 NumberStyles.AllowDecimalPoint 标志,则由 provider 指定的区域性的小数点符号可以出现在 s 中。

只有数字 0 可以显示为分析操作成功的小数位数;如果 fractional_digits 包含任何其他数字,则会引发 OverflowException
e “e”或“E”字符,指示该值以指数表示法表示。 如果 style 包含 NumberStyles.AllowExponent 标志,s 参数可以表示指数表示法中的数字。
hexdigits 从 0 到 f 或 0 到 F 的十六进制数字序列。

备注

无论 style 参数的值如何,分析操作都会忽略 s 中任何终止的 NUL (U+0000) 字符。

仅包含十进制数字(对应于 NumberStyles.None 样式)的字符串在 Int64 类型范围内时始终成功分析。 其余大部分 NumberStyles 成员控制可能但不需要存在于此输入字符串中的元素。 下表指示单个 NumberStyles 成员如何影响 s中可能存在的元素。

非复合 NumberStyles 值 除数字外允许的元素
NumberStyles.None 仅十进制数字。
NumberStyles.AllowDecimalPoint 小数点(.)和 小数位数 元素。 但是,小数位数 必须仅包含一个或多个数字或引发 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 必须是没有前缀的十六进制值。 例如,“C9AF3”已成功分析,但“0xC9AF3”不会。 style 中唯一可以存在的其他标志是 NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhite。 (NumberStyles 枚举具有包含两个空格标志的复合数字样式 NumberStyles.HexNumber

provider 参数是 IFormatProvider 实现,例如 NumberFormatInfoCultureInfo 对象。 provider 参数提供分析中使用的区域性特定信息。 如果 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