UInt16.Parse UInt16.Parse UInt16.Parse UInt16.Parse Method

定义

将数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number to its 16-bit unsigned integer equivalent.

重载

Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number in a specified style and culture-specific format to its 16-bit unsigned integer equivalent.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles)

将指定样式的数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number in a specified style to its 16-bit unsigned integer equivalent.

此方法与 CLS 不兼容。This method is not CLS-compliant. 符合 CLS 的替代方法是 Parse(String, NumberStyles)The CLS-compliant alternative is Parse(String, NumberStyles).

Parse(String) Parse(String) Parse(String) Parse(String)

将数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number to its 16-bit unsigned integer equivalent.

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

将指定区域性特定格式的数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number in a specified culture-specific format to its 16-bit unsigned integer equivalent.

Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider)

重要

此 API 不符合 CLS。

符合 CLS 的替代方案
System.Int32.Parse(String)

将指定样式和区域性特定格式的数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number in a specified style and culture-specific format to its 16-bit unsigned integer equivalent.

public:
 static System::UInt16 Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
[System.CLSCompliant(false)]
public static ushort Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> uint16
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As UShort

参数

s
String String String String

表示要转换的数字的字符串。A string that represents the number to convert. 该字符串使用由 style 参数指定的样式来进行解释。The string is interpreted by using the style specified by the style parameter.

style
NumberStyles NumberStyles NumberStyles NumberStyles

枚举值的按位组合,用于指示可出现在 s 中的样式元素。A bitwise combination of enumeration values that indicate the style elements that can be present in s. 要指定的一个典型值为 IntegerA typical value to specify is Integer.

provider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

一个对象,提供有关 s 的区域性特定格式设置信息。An object that supplies culture-specific formatting information about s.

返回

s 中指定的数字等效的 16 位无符号整数。A 16-bit unsigned integer equivalent to the number specified in s.

异常

style 不是 NumberStyles 值。style is not a NumberStyles value.

- 或 --or- style 不是 AllowHexSpecifierHexNumber 值的组合。style is not a combination of AllowHexSpecifier and HexNumber values.

s 的格式不符合 styles is not in a format compliant with style.

s 表示一个小于 MinValue 或大于 MaxValue 的数字。s represents a number that is less than MinValue or greater than MaxValue.

- 或 --or- s 包含非零的小数位。s includes non-zero, fractional digits.

示例

下面的示例使用Parse(String, NumberStyles, IFormatProvider)方法以将各种数字字符串表示形式转换为 16 位无符号的整数值。The following example uses the Parse(String, NumberStyles, IFormatProvider) method to convert various string representations of numbers to 16-bit unsigned integer values.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] cultureNames = { "en-US", "fr-FR" };
      NumberStyles[] styles= { NumberStyles.Integer, 
                               NumberStyles.Integer | NumberStyles.AllowDecimalPoint };
      string[] values = { "1702", "+1702.0", "+1702,0", "-1032.00",
                          "-1032,00", "1045.1", "1045,1" };
      
      // Parse strings using each culture
      foreach (string cultureName in cultureNames)
      {
         CultureInfo ci = new CultureInfo(cultureName);
         Console.WriteLine("Parsing strings using the {0} culture", 
                           ci.DisplayName);
         // Use each style.
         foreach (NumberStyles style in styles)
         {
            Console.WriteLine("   Style: {0}", style.ToString());
            // Parse each numeric string.
            foreach (string value in values)
            {
               try {
                  Console.WriteLine("      Converted '{0}' to {1}.", value, 
                                    UInt16.Parse(value, style, ci));
               }                                    
               catch (FormatException) {
                  Console.WriteLine("      Unable to parse '{0}'.", value);   
               }
               catch (OverflowException) {
                  Console.WriteLine("      '{0}' is out of range of the UInt16 type.", 
                                    value);
               }
            }
         }
      }   
   }
}
// The example displays the following output:
//       Parsing strings using the English (United States) culture
//          Style: Integer
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Unable to parse '+1702,0'.
//             Unable to parse '-1032.00'.
//             Unable to parse '-1032,00'.
//             Unable to parse '1045.1'.
//             Unable to parse '1045,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '1702' to 1702.
//             Converted '+1702.0' to 1702.
//             Unable to parse '+1702,0'.
//             '-1032.00' is out of range of the UInt16 type.
//             Unable to parse '-1032,00'.
//             '1045.1' is out of range of the UInt16 type.
//             Unable to parse '1045,1'.
//       Parsing strings using the French (France) culture
//          Style: Integer
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Unable to parse '+1702,0'.
//             Unable to parse '-1032.00'.
//             Unable to parse '-1032,00'.
//             Unable to parse '1045.1'.
//             Unable to parse '1045,1'.
//          Style: Integer, AllowDecimalPoint
//             Converted '1702' to 1702.
//             Unable to parse '+1702.0'.
//             Converted '+1702,0' to 1702.
//             Unable to parse '-1032.00'.
//             '-1032,00' is out of range of the UInt16 type.
//             Unable to parse '1045.1'.
//             '1045,1' is out of range of the UInt16 type.
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim cultureNames() As String = { "en-US", "fr-FR" }
      Dim styles() As NumberStyles = { NumberStyles.Integer, _
                                       NumberStyles.Integer Or NumberStyles.AllowDecimalPoint }
      Dim values() As String = { "1702", "+1702.0", "+1702,0", "-1032.00", _
                                 "-1032,00", "1045.1", "1045,1" }
      
      ' Parse strings using each culture
      For Each cultureName As String In cultureNames
         Dim ci As New CultureInfo(cultureName)
         Console.WriteLine("Parsing strings using the {0} culture", ci.DisplayName)
         ' Use each style.
         For Each style As NumberStyles In styles
            Console.WriteLine("   Style: {0}", style.ToString())
            ' Parse each numeric string.
            For Each value As String In values
               Try
                  Console.WriteLine("      Converted '{0}' to {1}.", value, _
                                    UInt16.Parse(value, style, ci))
               Catch e As FormatException
                  Console.WriteLine("      Unable to parse '{0}'.", value)   
               Catch e As OverflowException
                  Console.WriteLine("      '{0}' is out of range of the UInt16 type.", _
                                    value)         
               End Try
            Next
         Next
      Next                                    
   End Sub
End Module
' The example displays the following output:
'       Parsing strings using the English (United States) culture
'          Style: Integer
'             Converted '1702' to 1702.
'             Unable to parse '+1702.0'.
'             Unable to parse '+1702,0'.
'             Unable to parse '-1032.00'.
'             Unable to parse '-1032,00'.
'             Unable to parse '1045.1'.
'             Unable to parse '1045,1'.
'          Style: Integer, AllowDecimalPoint
'             Converted '1702' to 1702.
'             Converted '+1702.0' to 1702.
'             Unable to parse '+1702,0'.
'             '-1032.00' is out of range of the UInt16 type.
'             Unable to parse '-1032,00'.
'             '1045.1' is out of range of the UInt16 type.
'             Unable to parse '1045,1'.
'       Parsing strings using the French (France) culture
'          Style: Integer
'             Converted '1702' to 1702.
'             Unable to parse '+1702.0'.
'             Unable to parse '+1702,0'.
'             Unable to parse '-1032.00'.
'             Unable to parse '-1032,00'.
'             Unable to parse '1045.1'.
'             Unable to parse '1045,1'.
'          Style: Integer, AllowDecimalPoint
'             Converted '1702' to 1702.
'             Unable to parse '+1702.0'.
'             Converted '+1702,0' to 1702.
'             Unable to parse '-1032.00'.
'             '-1032,00' is out of range of the UInt16 type.
'             Unable to parse '1045.1'.
'             '1045,1' is out of range of the UInt16 type.

注解

style参数定义中允许的样式元素 (如空格或正或负号符号)s分析操作成功的参数。The style parameter defines the style elements (such as white space or the positive or negative sign symbol) that are allowed in the s parameter for the parse operation to succeed. 它必须是从位标志的组合NumberStyles枚举。It must be a combination of bit flags from the NumberStyles enumeration.

具体取决于值style,则s参数可能包含以下元素:Depending on the value of style, the s parameter may include the following elements:

[ws][$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws][ws][$][sign]digits[.fractional_digits][E[sign]exponential_digits][ws]

方括号 ([ and ]) 中的元素是可选的。Elements in square brackets ([ and ]) are optional. 如果style包括NumberStyles.AllowHexSpecifier,则s参数可能包含以下元素:If style includes NumberStyles.AllowHexSpecifier, the s parameter may include the following elements:

[ws]hexdigits[ws][ws]hexdigits[ws]

下表对每个元素进行了描述。The following table describes each element.

元素Element 描述Description
wsws 可选的空白区域。Optional white space. 空白可以出现在开头s如果style包括NumberStyles.AllowLeadingWhite标志,它可以出现在末尾s如果style包括NumberStyles.AllowTrailingWhite标志。White space can appear at the beginning of s if style includes the NumberStyles.AllowLeadingWhite flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingWhite flag.
$ 特定于区域性的货币符号。A culture-specific currency symbol. 在字符串中的位置由CurrencyPositivePattern的属性NumberFormatInfo返回的对象GetFormat方法的provider参数。Its position in the string is defined by the CurrencyPositivePattern property of the NumberFormatInfo object that is returned by the GetFormat method of the provider parameter. 货币符号可以出现在s如果style包括NumberStyles.AllowCurrencySymbol标志。The currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag.
signsign 一个可选符号后。An optional sign. (该方法将引发OverflowException如果s包含负号和表示一个非零数字。)符号可以显示在开头s如果style包括NumberStyles.AllowLeadingSign标志,它可以出现的末尾s如果style包括NumberStyles.AllowTrailingSign标志。(The method throws an OverflowException if s includes a negative sign and represents a non-zero number.) The sign can appear at the beginning of s if style includes the NumberStyles.AllowLeadingSign flag, and it can appear the end of s if style includes the NumberStyles.AllowTrailingSign flag. 可以在使用括号s指示负值style包括NumberStyles.AllowParentheses标志。Parentheses can be used in s to indicate a negative value if style includes the NumberStyles.AllowParentheses flag.
digitsdigits 从 0 到 9 的数字的序列。A sequence of digits from 0 through 9.
.. 特定于区域性的小数点符号。A culture-specific decimal point symbol. 当前区域性的小数点符号可以出现在s如果style包括NumberStyles.AllowDecimalPoint标志。The current culture's decimal point symbol can appear in s if style includes the NumberStyles.AllowDecimalPoint flag.
fractional_digitsfractional_digits 一个或多个数字 0-9 如果style包括NumberStyles.AllowExponent标志,或者一个或多个数字 0,如果不是。One or more occurrences of the digit 0-9 if style includes the NumberStyles.AllowExponent flag, or one or more occurrences of the digit 0 if it does not. 在中出现的小数位s仅当style包括NumberStyles.AllowDecimalPoint标志。Fractional digits can appear in s only if style includes the NumberStyles.AllowDecimalPoint flag.
EE "E"或者"E"字符,指示指数 (科学型) 表示法表示值。The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. s参数可以表示指数表示法的数字,如果style包括NumberStyles.AllowExponent标志。The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag.
exponential_digitsexponential_digits 从 0 到 9 的数字的序列。A sequence of digits from 0 through 9. s参数可以表示指数表示法的数字,如果style包括NumberStyles.AllowExponent标志。The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag.
hexdigitshexdigits 一系列十六进制数字从 0 到 f 或从 0 到 f。A sequence of hexadecimal digits from 0 through f, or 0 through F.

备注

中的任何终止 NUL (U + 0000) 字符s在分析操作,而不考虑的值,将忽略style参数。Any terminating NUL (U+0000) characters in s are ignored by the parsing operation, regardless of the value of the style argument.

仅带有十进制数字的字符串 (对应于NumberStyles.None样式) 总是可以分析成功。A string with decimal digits only (which corresponds to the NumberStyles.None style) always parses successfully. 其余的大多数NumberStyles成员控件可能会显示,但不是要求必须存在,此输入字符串中的元素。Most of the remaining NumberStyles members control elements that may be present, but are not required to be present, in this input string. 下表指示个别NumberStyles成员影响可能会出现在元素sThe following table indicates how individual NumberStyles members affect the elements that may be present in s.

非复合NumberStylesNon-composite NumberStyles values 元素中允许使用s除数字之外Elements permitted in s in addition to digits
NumberStyles.None 十进制数字。Decimal digits only.
NumberStyles.AllowDecimalPoint 小数点 () 和fractional_digits元素。The decimal point (.) and fractional_digits elements. 但是,如果样式不包括NumberStyles.AllowExponent标志, fractional_digits必须包含一个或多个数字 0; 否则为OverflowException引发。However, if style does not include the NumberStyles.AllowExponent flag, fractional_digits must consist of only one or more 0 digits; otherwise, an OverflowException is thrown.
NumberStyles.AllowExponent "E"或"E"字符,它指示指数记数法,连同exponential_digitsThe "e" or "E" character, which indicates exponential notation, along with exponential_digits.
NumberStyles.AllowLeadingWhite Ws开头的元素sThe ws element at the beginning of s.
NumberStyles.AllowTrailingWhite Ws结尾的元素sThe ws element at the end of s.
NumberStyles.AllowLeadingSign 登录之前位数A sign before digits.
NumberStyles.AllowTrailingSign 登录后的位数A sign after digits.
NumberStyles.AllowParentheses 之前和之后的括号位数以指示负值。Parentheses before and after digits to indicate a negative value.
NumberStyles.AllowThousands 组分隔符 () 元素。The group separator (,) element.
NumberStyles.AllowCurrencySymbol 货币 ($) 元素。The currency ($) element.

如果NumberStyles.AllowHexSpecifier使用标志,s必须是十六进制值。If the NumberStyles.AllowHexSpecifier flag is used, s must be a hexadecimal value. 有效的十六进制数字为 0 到 9、 a 到 f 和 A 到 f。诸如"0x"的前缀不受支持,使分析操作失败。Valid hexadecimal digits are 0 through 9, a through f, and A through F. A prefix, such as "0x", is not supported and causes the parse operation to fail. 其他标志只有可以结合NumberStyles.AllowHexSpecifierNumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteThe only other flags that can be combined with NumberStyles.AllowHexSpecifier are NumberStyles.AllowLeadingWhite and NumberStyles.AllowTrailingWhite. (NumberStyles枚举包括复合数字样式NumberStyles.HexNumber,其中包含这两个空白标志。)(The NumberStyles enumeration includes a composite number style, NumberStyles.HexNumber, that includes both white-space flags.)

备注

如果s参数是一个十六进制数字的字符串表示形式,则无法前面添加的任何修饰符 (如0x&h) 用于将其识别为十六进制数字。If the s parameter is the string representation of a hexadecimal number, it cannot be preceded by any decoration (such as 0x or &h) that differentiates it as a hexadecimal number. 这将导致分析操作引发异常。This causes the parse operation to throw an exception.

provider参数是IFormatProvider实现其GetFormat方法将返回NumberFormatInfo对象,它提供特定于区域性的格式信息sThe provider parameter is an IFormatProvider implementation whose GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of s. 有三种方法使用provider参数来提供到分析操作的自定义格式设置信息:There are three ways to use the provider parameter to supply custom formatting information to the parse operation:

如果providernull,则NumberFormatInfo对象使用当前区域性。If provider is null, the NumberFormatInfo object for the current culture is used.

另请参阅

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

重要

此 API 不符合 CLS。

[System.CLSCompliant(false)]
public static ushort Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = null);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> uint16
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = null) As UShort

参数

返回

Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles)

重要

此 API 不符合 CLS。

将指定样式的数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number in a specified style to its 16-bit unsigned integer equivalent.

此方法与 CLS 不兼容。This method is not CLS-compliant. 符合 CLS 的替代方法是 Parse(String, NumberStyles)The CLS-compliant alternative is Parse(String, NumberStyles).

public:
 static System::UInt16 Parse(System::String ^ s, System::Globalization::NumberStyles style);
[System.CLSCompliant(false)]
public static ushort Parse (string s, System.Globalization.NumberStyles style);
static member Parse : string * System.Globalization.NumberStyles -> uint16
Public Shared Function Parse (s As String, style As NumberStyles) As UShort

参数

s
String String String String

表示要转换的数字的字符串。A string that represents the number to convert. 该字符串使用由 style 参数指定的样式来进行解释。The string is interpreted by using the style specified by the style parameter.

style
NumberStyles NumberStyles NumberStyles NumberStyles

枚举值的按位组合,这些枚举值指定 s 所允许的格式。A bitwise combination of the enumeration values that specify the permitted format of s. 要指定的一个典型值为 IntegerA typical value to specify is Integer.

返回

s 中指定的数字等效的 16 位无符号整数。A 16-bit unsigned integer equivalent to the number specified in s.

异常

style 不是 NumberStyles 值。style is not a NumberStyles value.

- 或 --or- style 不是 AllowHexSpecifierHexNumber 值的组合。style is not a combination of AllowHexSpecifier and HexNumber values.

s 的格式不符合 styles is not in a format compliant with style.

s 表示一个小于 MinValue 或大于 MaxValue 的数字。s represents a number less than MinValue or greater than MaxValue.

- 或 --or- s 包含非零的小数位。s includes non-zero, fractional digits.

示例

以下示例尝试分析的字符串数组中每个元素,方法是使用多种NumberStyles值。The following example tries to parse each element in a string array by using a number of NumberStyles values.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      string[] values = { " 214 ", "1,064", "(0)", "1241+", " + 214 ", " +214 ", "2153.0", "1e03", "1300.0e-2" };
      NumberStyles whitespace =  NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite;
      NumberStyles[] styles = { NumberStyles.None, whitespace, 
                                NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign | whitespace, 
                                NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol, 
                                NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint };

      // Attempt to convert each number using each style combination.
      foreach (string value in values)
      {
         Console.WriteLine("Attempting to convert '{0}':", value);
         foreach (NumberStyles style in styles)
         {
            try {
               ushort number = UInt16.Parse(value, style);
               Console.WriteLine("   {0}: {1}", style, number);
            }   
            catch (FormatException) {
               Console.WriteLine("   {0}: Bad Format", style);
            }
         }
         Console.WriteLine();
      }
   }
}
// The example display the following output:
//    Attempting to convert ' 214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: 214
//       Integer, AllowTrailingSign: 214
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1,064':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: 1064
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '(0)':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '1241+':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 1241
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' + 214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert ' +214 ':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: 214
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: Bad Format
//    
//    Attempting to convert '2153.0':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 2153
//    
//    Attempting to convert '1e03':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 1000
//    
//    Attempting to convert '1300.0e-2':
//       None: Bad Format
//       AllowLeadingWhite, AllowTrailingWhite: Bad Format
//       Integer, AllowTrailingSign: Bad Format
//       AllowThousands, AllowCurrencySymbol: Bad Format
//       AllowDecimalPoint, AllowExponent: 13
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim values() As String = { " 214 ", "1,064", "(0)", "1241+", " + 214 ", " +214 ", "2153.0", "1e03", "1300.0e-2" }
      Dim whitespace As NumberStyles =  NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite
      Dim styles() As NumberStyles = { NumberStyles.None, _
                                       whitespace, _
                                       NumberStyles.AllowLeadingSign Or NumberStyles.AllowTrailingSign Or whitespace, _
                                       NumberStyles.AllowThousands Or NumberStyles.AllowCurrencySymbol, _
                                       NumberStyles.AllowExponent Or NumberStyles.AllowDecimalPoint }

      ' Attempt to convert each number using each style combination.
      For Each value As String In values
         Console.WriteLine("Attempting to convert '{0}':", value)
         For Each style As NumberStyles In styles
            Try
               Dim number As UShort = UInt16.Parse(value, style)
               Console.WriteLine("   {0}: {1}", style, number)
            Catch e As FormatException
               Console.WriteLine("   {0}: Bad Format", style)
            End Try         
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'    Attempting to convert ' 214 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: 214
'       Integer, AllowTrailingSign: 214
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '1,064':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: 1064
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '(0)':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '1241+':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 1241
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' + 214 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert ' +214 ':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: 214
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: Bad Format
'    
'    Attempting to convert '2153.0':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 2153
'    
'    Attempting to convert '1e03':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 1000
'    
'    Attempting to convert '1300.0e-2':
'       None: Bad Format
'       AllowLeadingWhite, AllowTrailingWhite: Bad Format
'       Integer, AllowTrailingSign: Bad Format
'       AllowThousands, AllowCurrencySymbol: Bad Format
'       AllowDecimalPoint, AllowExponent: 13

注解

style参数定义中允许的样式元素 (如空格、 正或负号符号、 组分隔符符号或十进制点符号)s分析操作成功的参数。The style parameter defines the style elements (such as white space, the positive or negative sign symbol, the group separator symbol, or the decimal point symbol) that are allowed in the s parameter for the parse operation to succeed. style 必须是中的位标志的组合NumberStyles枚举。style must be a combination of bit flags from the NumberStyles enumeration. style参数将使得此方法重载非常有用s包含十六进制值的字符串表示形式时数系 (十进制或十六进制) 由s仅在运行时,已知时,或者当你想要禁止的空白区域或正负符号sThe style parameter makes this method overload useful when s contains the string representation of a hexadecimal value, when the number system (decimal or hexadecimal) represented by s is known only at run time, or when you want to disallow white space or a sign symbol in s.

具体取决于值style,则s参数可能包含以下元素:Depending on the value of style, the s parameter may include the following elements:

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

方括号 ([ and ]) 中的元素是可选的。Elements in square brackets ([ and ]) are optional. 如果style包括NumberStyles.AllowHexSpecifier,则s参数可能包含下列元素:If style includes NumberStyles.AllowHexSpecifier, the s parameter may contain the following elements:

[ws]hexdigits[ws][ws]hexdigits[ws]

下表对每个元素进行了描述。The following table describes each element.

元素Element 描述Description
wsws 可选的空白区域。Optional white space. 空白可以出现在开头s如果style包括NumberStyles.AllowLeadingWhite标志,它可以出现在末尾s如果style包括NumberStyles.AllowTrailingWhite标志。White space can appear at the start of s if style includes the NumberStyles.AllowLeadingWhite flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingWhite flag.
$ 特定于区域性的货币符号。A culture-specific currency symbol. 在字符串中的位置由NumberFormatInfo.CurrencyNegativePatternNumberFormatInfo.CurrencyPositivePattern当前区域性的属性。Its position in the string is defined by the NumberFormatInfo.CurrencyNegativePattern and NumberFormatInfo.CurrencyPositivePattern properties of the current culture. 当前区域性的货币符号可以出现在s如果style包括NumberStyles.AllowCurrencySymbol标志。The current culture's currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag.
signsign 一个可选符号后。An optional sign. 符号可以显示在开头s如果style包括NumberStyles.AllowLeadingSign标志,它可以出现在末尾s如果style包括NumberStyles.AllowTrailingSign标志。The sign can appear at the start of s if style includes the NumberStyles.AllowLeadingSign flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingSign flag. 可以在使用括号s指示负值style包括NumberStyles.AllowParentheses标志。Parentheses can be used in s to indicate a negative value if style includes the NumberStyles.AllowParentheses flag. 但是,可以仅使用零; 使用负号符号否则,该方法将引发OverflowExceptionHowever, the negative sign symbol can be used only with zero; otherwise, the method throws an OverflowException.
digitsdigits

fractional_digitsfractional_digits

exponential_digitsexponential_digits
从 0 到 9 的数字的序列。A sequence of digits from 0 through 9. 有关fractional_digits、 仅数字 0 是有效。For fractional_digits, only the digit 0 is valid.
, 特定于区域性的组分隔符符号。A culture-specific group separator symbol. 当前区域性的组分隔符可以出现在s如果style包括NumberStyles.AllowThousands标志。The current culture's group separator can appear in s if style includes the NumberStyles.AllowThousands flag.
.. 特定于区域性的小数点符号。A culture-specific decimal point symbol. 当前区域性的小数点符号可以出现在s如果style包括NumberStyles.AllowDecimalPoint标志。The current culture's decimal point symbol can appear in s if style includes the NumberStyles.AllowDecimalPoint flag. 数字 0 可以显示为分析操作成功; 一个小数数字如果fractional_digits包括任何其他数字FormatException引发。Only the digit 0 can appear as a fractional digit for the parse operation to succeed; if fractional_digits includes any other digit, a FormatException is thrown.
EE "E"或者"E"字符,指示指数 (科学型) 表示法表示值。The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. s参数可以表示指数表示法的数字,如果style包括NumberStyles.AllowExponent标志。The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag.
hexdigitshexdigits 一系列十六进制数字从 0 到 f 或从 0 到 f。A sequence of hexadecimal digits from 0 through f, or 0 through F.

备注

中的任何终止 NUL (U + 0000) 字符s在分析操作,而不考虑的值,将忽略style参数。Any terminating NUL (U+0000) characters in s are ignored by the parsing operation, regardless of the value of the style argument.

仅为数字的字符串 (对应于NumberStyles.None样式) 总是可以分析成功。A string with digits only (which corresponds to the NumberStyles.None style) always parses successfully. 其余的大多数NumberStyles成员控件可能会显示,但不是要求是存在于输入字符串中的元素。Most of the remaining NumberStyles members control elements that may be present, but are not required to be present, in the input string. 下表指示个别NumberStyles成员影响可能会出现在元素sThe following table indicates how individual NumberStyles members affect the elements that may be present in s.

NumberStylesNumberStyles value 元素中允许使用s除数字之外Elements permitted in s in addition to digits
None 位数仅元素。The digits element only.
AllowDecimalPoint 小数点 (.) 和小数位数元素。The decimal point (.) and fractional-digits elements.
AllowExponent "E"或"E"字符,它指示指数记数法,连同exponential_digitsThe "e" or "E" character, which indicates exponential notation, along with exponential_digits.
AllowLeadingWhite Ws元素的开头sThe ws element at the start of s.
AllowTrailingWhite Ws结尾的元素sThe ws element at the end of s.
AllowLeadingSign 符号元素的开头sThe sign element at the start of s.
AllowTrailingSign 符号结尾的元素sThe sign element at the end of s.
AllowParentheses 登录形式的括号内包含的数字值的元素。The sign element in the form of parentheses enclosing the numeric value.
AllowThousands 组分隔符 (,) 元素。The group separator (,) element.
AllowCurrencySymbol 货币 ($) 元素中。The currency ($) element.
Currency 所有元素。All elements. 但是,s不能表示十六进制数或指数表示法的数字。However, s cannot represent a hexadecimal number or a number in exponential notation.
Float Ws元素的开头或末尾s登录开头处s,和小数点 () 符号。The ws element at the start or end of s, sign at the start of s, and the decimal point (.) symbol. s参数还可以使用指数记数法。The s parameter can also use exponential notation.
Number wssign,组分隔符 (),和小数点 () 元素。The ws, sign, group separator (,), and decimal point (.) elements.
Any 所有元素。All elements. 但是,s不能表示十六进制数。However, s cannot represent a hexadecimal number.

与其他不同NumberStyles值,该值允许,但不是需要,特定样式中的元素是否存在s,则NumberStyles.AllowHexSpecifier样式值意味着中的单个数字字符s始终解释为十六进制字符。Unlike the other NumberStyles values, which allow for, but do not require, the presence of particular style elements in s, the NumberStyles.AllowHexSpecifier style value means that the individual numeric characters in s are always interpreted as hexadecimal characters. 有效的十六进制字符是 0-9、 A-F 和 a-f。Valid hexadecimal characters are 0-9, A-F, and a-f. 诸如"0x"的前缀不受支持,使分析操作失败。A prefix, such as "0x", is not supported and causes the parse operation to fail. 其他标志只有可以结合style参数是NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteThe only other flags that can be combined with the style parameter are NumberStyles.AllowLeadingWhite and NumberStyles.AllowTrailingWhite. (NumberStyles枚举包括复合数字样式NumberStyles.HexNumber,其中包含这两个空白标志。)(The NumberStyles enumeration includes a composite number style, NumberStyles.HexNumber, that includes both white-space flags.)

备注

如果s的字符串表示形式的十六进制数,它不能带有任何修饰符 (如0x&h) 用于将其识别为十六进制数字。If s is the string representation of a hexadecimal number, it cannot be preceded by any decoration (such as 0x or &h) that differentiates it as a hexadecimal number. 这将导致转换失败。This causes the conversion to fail.

s通过使用中的格式设置信息分析参数NumberFormatInfo对象,将初始化为当前系统区域性。The s parameter is parsed by using the formatting information in a NumberFormatInfo object that is initialized for the current system culture. 若要指定其格式设置信息用于分析操作的区域性,调用Parse(String, NumberStyles, IFormatProvider)重载。To specify the culture whose formatting information is used for the parse operation, call the Parse(String, NumberStyles, IFormatProvider) overload.

另请参阅

Parse(String) Parse(String) Parse(String) Parse(String)

重要

此 API 不符合 CLS。

符合 CLS 的替代方案
System.Int32.Parse(String)

将数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number to its 16-bit unsigned integer equivalent.

public:
 static System::UInt16 Parse(System::String ^ s);
[System.CLSCompliant(false)]
public static ushort Parse (string s);
static member Parse : string -> uint16
Public Shared Function Parse (s As String) As UShort

参数

s
String String String String

表示要转换的数字的字符串。A string that represents the number to convert.

返回

s 中包含的数字等效的 16 位无符号整数。A 16-bit unsigned integer equivalent to the number contained in s.

异常

s 的格式不正确。s is not in the correct format.

s 表示一个小于 MinValue 或大于 MaxValue 的数字。s represents a number less than MinValue or greater than MaxValue.

示例

下面的示例调用Parse(String)方法将字符串数组中的每个元素转换为 16 位无符号整数。The following example calls the Parse(String) method to convert each element in a string array to an unsigned 16-bit integer.

using System;

public class Example
{
   public static void Main()
   {
      string[] values = { "-0", "17", "-12", "185", "66012", "+0", 
                          "", null, "16.1", "28.0", "1,034" };
      foreach (string value in values)
      {
         try {
            ushort number = UInt16.Parse(value);
            Console.WriteLine("'{0}' --> {1}", value, number);
         }
         catch (FormatException) {
            Console.WriteLine("'{0}' --> Bad Format", value);
         }
         catch (OverflowException) {   
            Console.WriteLine("'{0}' --> OverflowException", value);
         }
         catch (ArgumentNullException) {
            Console.WriteLine("'{0}' --> Null", value);
         }
      }                                 
   }
}
// The example displays the following output:
//       '-0' --> 0
//       '17' --> 17
//       '-12' --> OverflowException
//       '185' --> 185
//       '66012' --> OverflowException
//       '+0' --> 0
//       '' --> Bad Format
//       '' --> Null
//       '16.1' --> Bad Format
//       '28.0' --> Bad Format
//       '1,034' --> Bad Format
Module Example
   Public Sub Main()
      Dim values() As String = { "-0", "17", "-12", "185", "66012", _ 
                                 "+0", "", Nothing, "16.1", "28.0", _
                                 "1,034" }
      For Each value As String In values
         Try
            Dim number As UShort = UInt16.Parse(value)
            Console.WriteLine("'{0}' --> {1}", value, number)
         Catch e As FormatException
            Console.WriteLine("'{0}' --> Bad Format", value)
         Catch e As OverflowException   
            Console.WriteLine("'{0}' --> OverflowException", value)
         Catch e As ArgumentNullException
            Console.WriteLine("'{0}' --> Null", value)
         End Try
      Next                                 
   End Sub
End Module
' The example displays the following output:
'       '-0' --> 0
'       '17' --> 17
'       '-12' --> OverflowException
'       '185' --> 185
'       '66012' --> OverflowException
'       '+0' --> 0
'       '' --> Bad Format
'       '' --> Null
'       '16.1' --> Bad Format
'       '28.0' --> Bad Format
'       '1,034' --> Bad Format

注解

s参数应为以下形式的数字的字符串表示形式。The s parameter should be the string representation of a number in the following form.

[ws][sign]digits[ws][ws][sign]digits[ws]

方括号 ([ and ]) 中的元素是可选的。Elements in square brackets ([ and ]) are optional. 下表对每个元素进行了描述。The following table describes each element.

元素Element 描述Description
wsws 可选的空白区域。Optional white space.
signsign 一个可选符号后。An optional sign. 有效的符号字符由NumberFormatInfo.NegativeSignNumberFormatInfo.PositiveSign当前区域性的属性。Valid sign characters are determined by the NumberFormatInfo.NegativeSign and NumberFormatInfo.PositiveSign properties of the current culture. 但是,可以仅使用零; 使用负号符号否则,该方法将引发OverflowExceptionHowever, the negative sign symbol can be used only with zero; otherwise, the method throws an OverflowException.
digitsdigits 范围从 0 到 9 的数字的序列。A sequence of digits ranging from 0 to 9. 将忽略任何前导零。Any leading zeros are ignored.

备注

指定的字符串s参数解释使用NumberStyles.Integer样式。The string specified by the s parameter is interpreted by using the NumberStyles.Integer style. 不能包含任何组分隔符或小数分隔符,而且不能包含小数部分。It cannot contain any group separators or decimal separator, and it cannot have a decimal portion.

s通过使用中的格式设置信息分析参数System.Globalization.NumberFormatInfo对象,将初始化为当前系统区域性。The s parameter is parsed by using the formatting information in a System.Globalization.NumberFormatInfo object that is initialized for the current system culture. 有关详情,请参阅NumberFormatInfo.CurrentInfoFor more information, see NumberFormatInfo.CurrentInfo. 若要使用特定区域性的格式设置信息分析一个字符串,请使用Parse(String, IFormatProvider)方法。To parse a string by using the formatting information of a specific culture, use the Parse(String, IFormatProvider) method.

另请参阅

Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

重要

此 API 不符合 CLS。

符合 CLS 的替代方案
System.Int32.Parse(String)

将指定区域性特定格式的数字的字符串表示形式转换为它的等效 16 位无符号整数。Converts the string representation of a number in a specified culture-specific format to its 16-bit unsigned integer equivalent.

public:
 static System::UInt16 Parse(System::String ^ s, IFormatProvider ^ provider);
[System.CLSCompliant(false)]
public static ushort Parse (string s, IFormatProvider provider);
static member Parse : string * IFormatProvider -> uint16
Public Shared Function Parse (s As String, provider As IFormatProvider) As UShort

参数

s
String String String String

表示要转换的数字的字符串。A string that represents the number to convert.

provider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

一个对象,提供有关 s 的区域性特定格式设置信息。An object that supplies culture-specific formatting information about s.

返回

s 中指定的数字等效的 16 位无符号整数。A 16-bit unsigned integer equivalent to the number specified in s.

异常

s 的格式不正确。s is not in the correct format.

s 表示一个小于 MinValue 或大于 MaxValue 的数字。s represents a number less than MinValue or greater than MaxValue.

示例

下面的示例实例化使用两个加号 (+ +) 作为其正号的自定义区域性。The following example instantiates a custom culture that uses two plus signs (++) as its positive sign. 然后,它调用Parse(String, IFormatProvider)方法,以便通过分析的字符串数组CultureInfo表示此自定义区域性和固定区域性的对象。It then calls the Parse(String, IFormatProvider) method to parse an array of strings by using CultureInfo objects that represent both this custom culture and the invariant culture.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Define a custom culture that uses "++" as a positive sign. 
      CultureInfo ci = new CultureInfo("");
      ci.NumberFormat.PositiveSign = "++";
      // Create an array of cultures.
      CultureInfo[] cultures = { ci, CultureInfo.InvariantCulture };
      // Create an array of strings to parse.
      string[] values = { "++1403", "-0", "+0", "+16034", 
                          Int16.MinValue.ToString(), "14.0", "18012" };
      // Parse the strings using each culture.
      foreach (CultureInfo culture in cultures)
      {
         Console.WriteLine("Parsing with the '{0}' culture.", culture.Name);
         foreach (string value in values)
         {
            try {
               ushort number = UInt16.Parse(value, culture);
               Console.WriteLine("   Converted '{0}' to {1}.", value, number);
            }
            catch (FormatException) {
               Console.WriteLine("   The format of '{0}' is invalid.", value);
            }
            catch (OverflowException) {
               Console.WriteLine("   '{0}' is outside the range of a UInt16 value.", value);
            }               
         }
      }
   }
}
// The example displays the following output:
//       Parsing with the  culture.
//          Converted '++1403' to 1403.
//          Converted '-0' to 0.
//          The format of '+0' is invalid.
//          The format of '+16034' is invalid.
//          '-32768' is outside the range of a UInt16 value.
//          The format of '14.0' is invalid.
//          Converted '18012' to 18012.
//       Parsing with the '' culture.
//          The format of '++1403' is invalid.
//          Converted '-0' to 0.
//          Converted '+0' to 0.
//          Converted '+16034' to 16034.
//          '-32768' is outside the range of a UInt16 value.
//          The format of '14.0' is invalid.
//          Converted '18012' to 18012.
Imports System.Globalization

Module Example
   Public Sub Main()
      ' Define a custom culture that uses "++" as a positive sign. 
      Dim ci As CultureInfo = New CultureInfo("")
      ci.NumberFormat.PositiveSign = "++"
      ' Create an array of cultures.
      Dim cultures() As CultureInfo = { ci, CultureInfo.InvariantCulture }
      ' Create an array of strings to parse.
      Dim values() As String = { "++1403", "-0", "+0", "+16034", _
                                 Int16.MinValue.ToString(), "14.0", "18012" }
      ' Parse the strings using each culture.
      For Each culture As CultureInfo In cultures
         Console.WriteLine("Parsing with the '{0}' culture.", culture.Name)
         For Each value As String In values
            Try
               Dim number As UShort = UInt16.Parse(value, culture)
               Console.WriteLine("   Converted '{0}' to {1}.", value, number)
            Catch e As FormatException
               Console.WriteLine("   The format of '{0}' is invalid.", value)
            Catch e As OverflowException
               Console.WriteLine("   '{0}' is outside the range of a UInt16 value.", value)
            End Try               
         Next
      Next
   End Sub
End Module
' The example displays the following output:
'       Parsing with the  culture.
'          Converted '++1403' to 1403.
'          Converted '-0' to 0.
'          The format of '+0' is invalid.
'          The format of '+16034' is invalid.
'          '-32768' is outside the range of a UInt16 value.
'          The format of '14.0' is invalid.
'          Converted '18012' to 18012.
'       Parsing with the '' culture.
'          The format of '++1403' is invalid.
'          Converted '-0' to 0.
'          Converted '+0' to 0.
'          Converted '+16034' to 16034.
'          '-32768' is outside the range of a UInt16 value.
'          The format of '14.0' is invalid.
'          Converted '18012' to 18012.

注解

s参数包含多个窗体:The s parameter contains a number of the form:

[ws][sign]digits[ws][ws][sign]digits[ws]

在方括号 ([和]) 是可选的项。Items in square brackets ([ and ]) are optional. 下表对每个元素进行了描述。The following table describes each element.

元素Element 描述Description
wsws 可选的空白区域。Optional white space.
Signsign 一个可选符号后或负号如果s表示值为零。An optional sign, or a negative sign if s represents the value zero.
数字digits 范围从 0 到 9 的数字的序列。A sequence of digits ranging from 0 to 9.

使用解释 s 参数NumberStyles.Integer样式。The s parameter is interpreted using the NumberStyles.Integer style. 除了字节值的十进制数字,允许仅前导空格和尾随空格以及前导符号。In addition to the byte value's decimal digits, only leading and trailing spaces along with a leading sign is allowed. (如果存在,负号,则s必须代表的值为零或该方法将引发OverflowException。)若要显式定义的样式元素以及可出现在特定于区域性的格式设置信息s,使用Parse(String, NumberStyles, IFormatProvider)方法。(If the negative sign is present, s must represent a value of zero or the method throws an OverflowException.) To explicitly define the style elements together with the culture-specific formatting information that can be present in s, use the Parse(String, NumberStyles, IFormatProvider) method.

provider参数是IFormatProvider实现其GetFormat方法将返回NumberFormatInfo对象,它提供特定于区域性的格式信息sThe provider parameter is an IFormatProvider implementation whose GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of s. 有三种方法使用provider参数来提供到分析操作的自定义格式设置信息:There are three ways to use the provider parameter to supply custom formatting information to the parse operation:

如果providernull,则NumberFormatInfo使用当前区域性。If provider is null, the NumberFormatInfo for the current culture is used.

另请参阅

适用于