BigInteger.TryParse BigInteger.TryParse BigInteger.TryParse BigInteger.TryParse Method

定義

数値の文字列形式を対応する BigInteger 表現に変換できるかどうかを試行し、変換に成功したかどうかを示す値を返します。Tries to convert the string representation of a number to its BigInteger equivalent, and returns a value that indicates whether the conversion succeeded.

オーバーロード

TryParse(ReadOnlySpan<Char>, BigInteger) TryParse(ReadOnlySpan<Char>, BigInteger) TryParse(ReadOnlySpan<Char>, BigInteger) TryParse(ReadOnlySpan<Char>, BigInteger)
TryParse(String, BigInteger) TryParse(String, BigInteger) TryParse(String, BigInteger) TryParse(String, BigInteger)

数値の文字列形式を対応する BigInteger 表現に変換できるかどうかを試行し、変換に成功したかどうかを示す値を返します。Tries to convert the string representation of a number to its BigInteger equivalent, and returns a value that indicates whether the conversion succeeded.

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger)
TryParse(String, NumberStyles, IFormatProvider, BigInteger) TryParse(String, NumberStyles, IFormatProvider, BigInteger) TryParse(String, NumberStyles, IFormatProvider, BigInteger) TryParse(String, NumberStyles, IFormatProvider, BigInteger)

指定されたスタイルおよびカルチャ固有の書式の数値の文字列形式を等価の BigInteger に変換できるかどうかを試行し、変換に成功したかどうかを示す値を返します。Tries to convert the string representation of a number in a specified style and culture-specific format to its BigInteger equivalent, and returns a value that indicates whether the conversion succeeded.

TryParse(ReadOnlySpan<Char>, BigInteger) TryParse(ReadOnlySpan<Char>, BigInteger) TryParse(ReadOnlySpan<Char>, BigInteger) TryParse(ReadOnlySpan<Char>, BigInteger)

public:
 static bool TryParse(ReadOnlySpan<char> value, [Runtime::InteropServices::Out] System::Numerics::BigInteger % result);
public static bool TryParse (ReadOnlySpan<char> value, out System.Numerics.BigInteger result);
static member TryParse : ReadOnlySpan<char> *  -> bool
Public Shared Function TryParse (value As ReadOnlySpan(Of Char), ByRef result As BigInteger) As Boolean

パラメーター

戻り値

TryParse(String, BigInteger) TryParse(String, BigInteger) TryParse(String, BigInteger) TryParse(String, BigInteger)

数値の文字列形式を対応する BigInteger 表現に変換できるかどうかを試行し、変換に成功したかどうかを示す値を返します。Tries to convert the string representation of a number to its BigInteger equivalent, and returns a value that indicates whether the conversion succeeded.

public:
 static bool TryParse(System::String ^ value, [Runtime::InteropServices::Out] System::Numerics::BigInteger % result);
public static bool TryParse (string value, out System.Numerics.BigInteger result);
static member TryParse : string *  -> bool
Public Shared Function TryParse (value As String, ByRef result As BigInteger) As Boolean

パラメーター

value
String String String String

数値の文字列形式。The string representation of a number.

result
BigInteger BigInteger BigInteger BigInteger

このメソッドから制御が戻るときに、value に含まれる数値と等価の BigInteger が格納されます。変換に失敗した場合は 0 が格納されます。When this method returns, contains the BigInteger equivalent to the number that is contained in value, or zero (0) if the conversion fails. value パラメーターが null の場合、または正しい形式ではない場合、変換は失敗します。The conversion fails if the value parameter is null or is not of the correct format. このパラメーターは初期化せずに渡されます。This parameter is passed uninitialized.

戻り値

true が正常に変換された場合は value。それ以外の場合は falsetrue if value was converted successfully; otherwise, false.

例外

次の例では、 TryParse(String, BigInteger) 2 つのインスタンスを作成するメソッドBigIntegerオブジェクト。The following example uses the TryParse(String, BigInteger) method to instantiate two BigInteger objects. 各オブジェクトを他の数値を乗算し、呼び出して、変換が成功した場合、、Compareメソッドを 2 つのオブジェクト間の関係を決定します。If the conversions succeed, it multiplies each object by another number and then calls the Compare method to determine the relationship between the two objects.

BigInteger number1, number2;
bool succeeded1 = BigInteger.TryParse("-12347534159895123", out number1);
bool succeeded2 = BigInteger.TryParse("987654321357159852", out number2);
if (succeeded1 && succeeded2)
{
   number1 *= 3;
   number2 *= 2;
   switch (BigInteger.Compare(number1, number2))
   {
      case -1:
         Console.WriteLine("{0} is greater than {1}.", number2, number1);
         break;
      case 0:
         Console.WriteLine("{0} is equal to {1}.", number1, number2);
         break;
      case 1:
         Console.WriteLine("{0} is greater than {1}.", number1, number2);
         break;
   }      
}
else
{
   if (! succeeded1) 
      Console.WriteLine("Unable to initialize the first BigInteger value.");

   if (! succeeded2)
      Console.WriteLine("Unable to initialize the second BigInteger value.");
}
// The example displays the following output:
//      1975308642714319704 is greater than -37042602479685369.
Dim number1 As BigInteger = BigInteger.Zero
Dim number2 As BigInteger = BigInteger.Zero
Dim succeeded1 As Boolean = BigInteger.TryParse("-12347534159895123", number1)
Dim succeeded2 As Boolean = BigInteger.TryParse("987654321357159852", number2)
If succeeded1 AndAlso succeeded2
   number1 *= 3
   number2 *= 2
   Select Case BigInteger.Compare(number1, number2)
      Case -1
         Console.WriteLine("{0} is greater than {1}.", number2, number1)
      Case 0
         Console.WriteLine("{0} is equal to {1}.", number1, number2)
      Case 1
         Console.WriteLine("{0} is greater than {1}.", number1, number2)
   End Select      
Else
   If Not succeeded1 Then 
      Console.WriteLine("Unable to initialize the first BigInteger value.")
   End If
   If Not succeeded2 Then
      Console.WriteLine("Unable to initialize the second BigInteger value.")
   
   End If
End If
' The example displays the following output:
'      1975308642714319704 is greater than -37042602479685369.

注釈

TryParse(String, BigInteger)などのメソッドは、Parse(String)メソッド、点を除いて、変換が失敗した場合、その it が例外をスローしません。The TryParse(String, BigInteger) method is like the Parse(String) method, except that it does not throw an exception if the conversion fails. このメソッドをテストする例外処理を使用する必要はありません、FormatException場合value有効でないし、正常に解析されることはできません。This method eliminates the need to use exception handling to test for a FormatException if value is invalid and cannot be successfully parsed.

valueパラメーターは、次の形式の 10 進数の文字列形式を指定する必要があります。The value parameter should be the string representation of a decimal number in the following form:

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

角かっこ ([ および ]) 内の要素は省略可能です。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.
数字digits 10 進数字の 0 から 9 までのシーケンス。A sequence of decimal digits ranging from 0 to 9.

注意

指定された文字列、valueパラメーターは、グループ区切り記号または 10 進数の区切り記号を含めることはできず、小数部を持つことはできません。The string specified by the value parameter cannot contain any group separators or decimal separator, and it cannot have a decimal portion.

valueパラメーターを使用して解釈されます、NumberStyles.Integerスタイル。The value parameter is interpreted by using the NumberStyles.Integer style. 10 進の数字だけでなくには、先頭と末尾のスペースを先頭の符号のみを許可します。In addition to the decimal digits, only leading and trailing spaces with a leading sign are allowed. 使用できるカルチャに固有の書式情報を持つスタイル要素を明示的に定義するvalueを呼び出し、TryParse(String, NumberStyles, IFormatProvider, BigInteger)メソッド。To explicitly define the style elements with the culture-specific formatting information that can be present in value, call the TryParse(String, NumberStyles, IFormatProvider, BigInteger) method.

valueで書式設定情報を使用してパラメーターを解析するNumberFormatInfo現在のカルチャ オブジェクト。The value parameter is parsed by using the formatting information in a NumberFormatInfo object for the current culture. 詳細については、「NumberFormatInfo.CurrentInfo」を参照してください。For more information, see NumberFormatInfo.CurrentInfo.

このオーバー ロード内のすべての桁を解釈し、valueとして 10 進数字のパラメーター。This overload interprets all digits in the value parameter as decimal digits. 16 進数の文字列表現を解析する、TryParse(String, NumberStyles, IFormatProvider, BigInteger)オーバー ロードを代用します。To parse the string representation of a hexadecimal number, call the TryParse(String, NumberStyles, IFormatProvider, BigInteger) overload instead.

こちらもご覧ください

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger)

public:
 static bool TryParse(ReadOnlySpan<char> value, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Numerics::BigInteger % result);
public static bool TryParse (ReadOnlySpan<char> value, System.Globalization.NumberStyles style, IFormatProvider provider, out System.Numerics.BigInteger result);
static member TryParse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider *  -> bool
Public Shared Function TryParse (value As ReadOnlySpan(Of Char), style As NumberStyles, provider As IFormatProvider, ByRef result As BigInteger) As Boolean

パラメーター

戻り値

TryParse(String, NumberStyles, IFormatProvider, BigInteger) TryParse(String, NumberStyles, IFormatProvider, BigInteger) TryParse(String, NumberStyles, IFormatProvider, BigInteger) TryParse(String, NumberStyles, IFormatProvider, BigInteger)

指定されたスタイルおよびカルチャ固有の書式の数値の文字列形式を等価の BigInteger に変換できるかどうかを試行し、変換に成功したかどうかを示す値を返します。Tries to convert the string representation of a number in a specified style and culture-specific format to its BigInteger equivalent, and returns a value that indicates whether the conversion succeeded.

public:
 static bool TryParse(System::String ^ value, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Numerics::BigInteger % result);
public static bool TryParse (string value, System.Globalization.NumberStyles style, IFormatProvider provider, out System.Numerics.BigInteger result);
static member TryParse : string * System.Globalization.NumberStyles * IFormatProvider *  -> bool
Public Shared Function TryParse (value As String, style As NumberStyles, provider As IFormatProvider, ByRef result As BigInteger) As Boolean

パラメーター

value
String String String String

数値の文字列形式。The string representation of a number. 文字列は、style で指定されたスタイルを使用して解釈されます。The string is interpreted using the style specified by style.

style
NumberStyles NumberStyles NumberStyles NumberStyles

value で存在する可能性を持つスタイル要素を示す、列挙値のビットごとの組み合わせ。A bitwise combination of enumeration values that indicates the style elements that can be present in value. 通常指定する値は、Integer です。A typical value to specify is Integer.

provider
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

value に関するカルチャ固有の書式情報を提供するオブジェクト。An object that supplies culture-specific formatting information about value.

result
BigInteger BigInteger BigInteger BigInteger

このメソッドから制御が戻るときに、value に含まれる数値と等価の BigInteger が格納されます。変換に失敗した場合は Zero が格納されます。When this method returns, contains the BigInteger equivalent to the number that is contained in value, or Zero if the conversion failed. value パラメーターが null の場合、または style に従った形式ではない場合、変換は失敗します。The conversion fails if the value parameter is null or is not in a format that is compliant with style. このパラメーターは初期化せずに渡されます。This parameter is passed uninitialized.

戻り値

value パラメーターが正常に変換された場合は true。それ以外の場合は falsetrue if the value parameter was converted successfully; otherwise, false.

例外

styleNumberStyles 値ではありません。style is not a NumberStyles value.

または-or- style には、別の値と共に AllowHexSpecifier または HexNumber フラグが含まれます。style includes the AllowHexSpecifier or HexNumber flag along with another value.

次の例でいくつかの呼び出し、TryParse(String, NumberStyles, IFormatProvider, BigInteger)メソッドの値のさまざまな組み合わせを使用して、styleproviderパラメーター。The following example makes some calls to the TryParse(String, NumberStyles, IFormatProvider, BigInteger) method using various combinations of values for the style and provider parameters.

string numericString;
BigInteger number = BigInteger.Zero;

// Call TryParse with default values of style and provider.
numericString = "  -300   ";
if (BigInteger.TryParse(numericString, NumberStyles.Integer, 
                       null, out number))
   Console.WriteLine("'{0}' was converted to {1}.", 
                     numericString, number);                    
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.", 
                     numericString);

// Call TryParse with the default value of style and 
// a provider supporting the tilde as negative sign.
numericString = "  -300   ";
if (BigInteger.TryParse(numericString, NumberStyles.Integer,
                       new BigIntegerFormatProvider(), out number))
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number);                             
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString);

// Call TryParse with only AllowLeadingWhite and AllowTrailingWhite.
// Method returns false because of presence of negative sign.
numericString = "  -500   ";
if (BigInteger.TryParse(numericString,
                        NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite,
                        new BigIntegerFormatProvider(), out number))
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number);                             
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString);

// Call TryParse with AllowHexSpecifier and a hex value.
numericString = "F14237FFAAC086455192";
if (BigInteger.TryParse(numericString,
                        NumberStyles.AllowHexSpecifier,
                        null, out number))
   Console.WriteLine("'{0}' was converted to {1} (0x{1:x}).",
                     numericString, number);                             
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString);

// Call TryParse with AllowHexSpecifier and a negative hex value.
// Conversion fails because of presence of negative sign.
numericString = "-3af";
if (BigInteger.TryParse(numericString, NumberStyles.AllowHexSpecifier,
                       new BigIntegerFormatProvider(), out number))
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number);       
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString);

// Call TryParse with only NumberStyles.None.
// Conversion fails because of presence of white space and sign.
numericString = " -300 ";
if (BigInteger.TryParse(numericString, NumberStyles.None,
                       new BigIntegerFormatProvider(), out number))
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number);         
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString);
                                            
// Call TryParse with NumberStyles.Any and a provider for the fr-FR culture.
// Conversion fails because the string is formatted for the en-US culture.
numericString = "9,031,425,666,123,546.00";
if (BigInteger.TryParse(numericString, NumberStyles.Any,
                       new CultureInfo("fr-FR"), out number))
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number);                     
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString);

// Call TryParse with NumberStyles.Any and a provider for the fr-FR culture.
// Conversion succeeds because the string is properly formatted 
// For the fr-FR culture.
numericString = "9 031 425 666 123 546,00";
if (BigInteger.TryParse(numericString, NumberStyles.Any,
                       new CultureInfo("fr-FR"), out number))
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number);                 
else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString);
// The example displays the following output:
//    '  -300   ' was converted to -300.
//    Conversion of '  -300   ' to a BigInteger failed.
//    Conversion of '  -500   ' to a BigInteger failed.
//    'F14237FFAAC086455192' was converted to -69613977002644837412462 (0xf14237ffaac086455192).
//    Conversion of '-3af' to a BigInteger failed.
//    Conversion of ' -300 ' to a BigInteger failed.
//    Conversion of '9,031,425,666,123,546.00' to a BigInteger failed.
//    '9 031 425 666 123 546,00' was converted to 9031425666123546.      
Dim numericString As String
Dim number As BigInteger = BigInteger.Zero

' Call TryParse with default values of style and provider.
numericString = "  -300   "
If BigInteger.TryParse(numericString, NumberStyles.Integer,
                       Nothing, number) Then
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If                                             

' Call TryParse with the default value of style and 
' a provider supporting the tilde as negative sign.
numericString = "  -300   "
If BigInteger.TryParse(numericString, NumberStyles.Integer,
                       New BigIntegerFormatProvider(), number) Then
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If                                             

' Call TryParse with only AllowLeadingWhite and AllowTrailingWhite.
' Method returns false because of presence of negative sign.
numericString = "  -500   "
If BigInteger.TryParse(numericString,
                    NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite,
                    New BigIntegerFormatProvider(), number) Then
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If                                             

' Call TryParse with AllowHexSpecifier and a hex value.
numericString = "F14237FFAAC086455192"
If BigInteger.TryParse(numericString,
                    NumberStyles.AllowHexSpecifier,
                    Nothing, number) Then
   Console.WriteLine("'{0}' was converted to {1} (0x{1:x}).",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If                                             

' Call TryParse with AllowHexSpecifier and a negative hex value.
' Conversion fails because of presence of negative sign.
numericString = "-3af"
If BigInteger.TryParse(numericString, NumberStyles.AllowHexSpecifier,
                       New BigIntegerFormatProvider(), number) Then
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If                                             

' Call TryParse with only NumberStyles.None.
' Conversion fails because of presence of white space and sign.
numericString = " -300 "
If BigInteger.TryParse(numericString, NumberStyles.None,
                       New BigIntegerFormatProvider(), number) Then
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If 
                                            
' Call TryParse with NumberStyles.Any and a provider for the fr-FR culture.
' Conversion fails because the string is formatted for the en-US culture.
numericString = "9,031,425,666,123,546.00"
If BigInteger.TryParse(numericString, NumberStyles.Any,
                       New CultureInfo("fr-FR"), number) Then
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If

' Call TryParse with NumberStyles.Any and a provider for the fr-FR culture.
' Conversion succeeds because the string is properly formatted 
' For the fr-FR culture.
numericString = "9 031 425 666 123 546,00"
If BigInteger.TryParse(numericString, NumberStyles.Any,
                       New CultureInfo("fr-FR"), number) Then
   Console.WriteLine("'{0}' was converted to {1}.",
                     numericString, number)                             
Else
   Console.WriteLine("Conversion of '{0}' to a BigInteger failed.",
                     numericString)
End If
' The example displays the following output:
'    '  -300   ' was converted to -300.
'    Conversion of '  -300   ' to a BigInteger failed.
'    Conversion of '  -500   ' to a BigInteger failed.
'    'F14237FFAAC086455192' was converted to -69613977002644837412462 (0xf14237ffaac086455192).
'    Conversion of '-3af' to a BigInteger failed.
'    Conversion of ' -300 ' to a BigInteger failed.
'    Conversion of '9,031,425,666,123,546.00' to a BigInteger failed.
'    '9 031 425 666 123 546,00' was converted to 9031425666123546.      

個々 の呼び出し数、TryParse(String, NumberStyles, IFormatProvider, BigInteger)メソッドは、次のインスタンスを渡すBigIntegerFormatProviderクラスは、負の符号としてティルダ (~) を定義します。A number of the individual calls to the TryParse(String, NumberStyles, IFormatProvider, BigInteger) method pass an instance of the following BigIntegerFormatProvider class, which defines a tilde (~) as the negative sign.

public class BigIntegerFormatProvider : IFormatProvider
{
   public object GetFormat(Type formatType) 
   {
      if (formatType == typeof(NumberFormatInfo)) 
      {
         NumberFormatInfo numberFormat = new NumberFormatInfo();
         numberFormat.NegativeSign = "~";
         return numberFormat;
      }
      else
      {
         return null;
      }      
   }
}
Public Class BigIntegerFormatProvider : Implements IFormatProvider
   Public Function GetFormat(formatType As Type) As Object _
                            Implements IFormatProvider.GetFormat
      If formatType Is GetType(NumberFormatInfo) Then
         Dim numberFormat As New NumberFormatInfo
         numberFormat.NegativeSign = "~"
         Return numberFormat
      Else
         Return Nothing
      End If      
   End Function
End Class

注釈

TryParse(String, NumberStyles, IFormatProvider, BigInteger)などのメソッドは、Parse(String, NumberStyles, IFormatProvider)メソッド、点を除いて、変換が失敗した場合、その it が例外をスローしません。The TryParse(String, NumberStyles, IFormatProvider, BigInteger) method is like the Parse(String, NumberStyles, IFormatProvider) method, except that it does not throw an exception if the conversion fails. このメソッドをテストする例外処理を使用する必要はありません、FormatException場合value有効でないし、正常に解析されたことはできません。This method eliminates the need to use exception handling to test for a FormatException if value is invalid and cannot be parsed successfully.

style (空白や正または負符号) で使用できるスタイル要素を定義するパラメーター、value解析操作が成功するためのパラメーター。The style parameter defines the style elements (such as white space or a positive or negative sign) that are allowed in the value parameter for the parse operation to succeed. ビット フラグの組み合わせがあります、NumberStyles列挙体。It must be a combination of bit flags from the NumberStyles enumeration. 値に応じてstylevalueパラメーターは、次の要素を含めることができます。Depending on the value of style, the value 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]

場合、styleパラメーターが含まれるAllowHexSpecifiervalueパラメーターは、次の要素を含めることができます。If the style parameter includes AllowHexSpecifier, the value parameter may include the following elements:

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

角かっこ ([ および ]) 内の要素は省略可能です。Elements in square brackets ([ and ]) are optional. 次の表は、それぞれの要素の説明です。The following table describes each element.

要素Element 説明Description
wsws 空白文字の省略可能です。Optional white space. 先頭に空白文字を表示できるvalue場合styleが含まれています、NumberStyles.AllowLeadingWhiteフラグ、または末尾のvalue場合styleが含まれています、NumberStyles.AllowTrailingWhiteフラグ。White space can appear at the start of value if style includes the NumberStyles.AllowLeadingWhite flag, or at the end of value 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 returned by the GetFormat method of the provider parameter. 通貨記号に表示されるvalue場合styleが含まれています、NumberStyles.AllowCurrencySymbolフラグ。The currency symbol can appear in value if style includes the NumberStyles.AllowCurrencySymbol flag.
signsign オプションの符号。An optional sign. 先頭に表示できる符号value場合styleが含まれています、NumberStyles.AllowLeadingSignの最後に、フラグ、およびそれが表示されるvalue場合styleが含まれています、NumberStyles.AllowTrailingSignフラグ。The sign can appear at the start of value if style includes the NumberStyles.AllowLeadingSign flag, and it can appear at the end of value if style includes the NumberStyles.AllowTrailingSign flag. かっこを使用できるvalue負の値を指定する場合styleが含まれています、NumberStyles.AllowParenthesesフラグ。Parentheses can be used in value to indicate a negative value if style includes the NumberStyles.AllowParentheses flag.
数字digits 0 ~ 9 桁の数字のシーケンス。A sequence of digits from 0 through 9.
, カルチャ固有のグループ区切り記号。A culture-specific group separator. 指定されたカルチャの桁区切り記号providerに表示できるvalue場合styleが含まれています、NumberStyles.AllowThousandsフラグ。The group separator of the culture specified by provider can appear in value if style includes the NumberStyles.AllowThousands flag.
.. カルチャに固有の小数点記号。A culture-specific decimal point symbol. 指定されたカルチャの小数点記号providerに表示できるvalue場合styleが含まれています、NumberStyles.AllowDecimalPointフラグ。The decimal point symbol of the culture specified by provider can appear in value if style includes the NumberStyles.AllowDecimalPoint flag.
fractional_digitsfractional_digits 1 つ以上の数字の 0。One or more occurrences of the digit 0. 小数部の桁数を表示できるvalue場合にのみstyleが含まれています、NumberStyles.AllowDecimalPointフラグ。Fractional digits can appear in value 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. valueパラメーターは指数表記の数値を表すことができる場合styleが含まれています、NumberStyles.AllowExponentフラグ。The value 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. valueパラメーターは指数表記の数値を表すことができる場合styleが含まれています、NumberStyles.AllowExponentフラグ。The value parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag.
hexdigitshexdigits 0 ~ f、または f の 0 から 16 進数のシーケンス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.

10 進数字のみを含む文字列 (に対応する、NumberStyles.Noneフラグ) を常に正常に解析します。A string with decimal digits only (which corresponds to the NumberStyles.None flag) 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メンバー内に存在する要素に影響を与えるvalueします。The following table indicates how individual NumberStyles members affect the elements that may be present in value.

非コンポジットNumberStylesNon-composite NumberStyles values 数字以外の値で使用できる要素Elements permitted in value in addition to digits
None 10 進数字のみです。Decimal digits only.
AllowDecimalPoint 10 進数のポイント (.) とfractional_digits要素。The decimal point (.) and fractional_digits elements. ただし、 fractional_digits 0 のみの 1 つ以上の数字、または、メソッドが返すので構成されている必要がありますfalseします。However, fractional_digits must consist of only one or more 0 digits, or the method returns false.
AllowExponent "E"または"E"文字と共に、指数表記を示すexponential_digitsします。The "e" or "E" character, which indicates exponential notation, along with exponential_digits. 場合valueの数値を表す、指数表記では、0 以外の小数部のコンポーネントを持つことはできません。If value represents a number in exponential notation, it cannot have a non-zero, fractional component.
AllowLeadingWhite Ws要素の開始時valueします。The ws element at the start of value.
AllowTrailingWhite Wsの末尾にある要素valueします。The ws element at the end of value.
AllowLeadingSign サインオン要素の前にします。The sign element before digits.
AllowTrailingSign サインオン要素の後にします。The sign element after digits.
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. ただし、 value 16 進数または指数表記の数値を表すことはできません。However, value cannot represent a hexadecimal number or a number in exponential notation.
Float Ws先頭または末尾に要素valueサインオンの開始時value、および小数点 (.) シンボル。The ws element at the start or end of value, sign at the start of value, and the decimal point (.) symbol. valueパラメーターは、指数表記も使用できます。The value parameter can also use exponential notation.
Number Wsサインオン、桁区切り記号 ()、および小数点 10 進数 (.) 要素。The ws, sign, group separator (,), and decimal point (.) elements.
Any すべての要素。All elements. ただし、 value 16 進数を表すことはできません。However, value cannot represent a hexadecimal number.

重要

使用する場合、TryParse文字列表現をラウンドト リップさせる方法のBigIntegerによって出力された値、ToStringメソッドを使用する必要がある、BigInteger.ToString(String)メソッドの文字列表現を生成する"R"書式指定子、BigInteger値。If you use the TryParse method to round-trip the string representation of a BigInteger value that was output by the ToString method, you should use the BigInteger.ToString(String) method with the "R" format specifier to generate the string representation of the BigInteger value. それ以外の場合の文字列表現、 BigInteger 、50、元の値とデータの最上位桁数が失われるを使用する場合のみが保持されます、TryParseを復元する方法、BigInteger値。Otherwise, the string representation of the BigInteger preserves only the 50 most significant digits of the original value, and data may be lost when you use the TryParse method to restore the BigInteger value.

場合、NumberStyles.AllowHexSpecifierフラグを使用すると、 value 16 進数の値を指定する必要があります。If the NumberStyles.AllowHexSpecifier flag is used, value must be a hexadecimal value. 他のフラグのみに存在することができるstyleNumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhiteします。The only other flags that can be present in style are NumberStyles.AllowLeadingWhite and NumberStyles.AllowTrailingWhite. (、NumberStyles列挙には複合スタイルは、 HexNumber、空白文字の両方のフラグが含まれます)。(The NumberStyles enumeration has a composite style, HexNumber, that includes both white-space flags.)

注意

場合value文字列表現ですが、16 進数は、接頭辞前ことはできません (など0xまたは&h)、16 進数として区別します。If value 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.

場合value16 進数の文字列、TryParse(String, NumberStyles, IFormatProvider, BigInteger)メソッドは解釈valueその最初の 2 つの 16 進数の数字がより大きいか等しい場合は、2 の補数表現を使用して、格納されている負の数値として0x80します。If value is a hexadecimal string, the TryParse(String, NumberStyles, IFormatProvider, BigInteger) method interprets value as a negative number stored by using two's complement representation if its first two hexadecimal digits are greater than or equal to 0x80. つまり、メソッドは、最初のバイトの最上位ビットを解釈value符号ビットとして。In other words, the method interprets the highest-order bit of the first byte in value as the sign bit. 16 進数の文字列が正の数の最初の桁として正しく解釈されるかどうかを確認するvalue値が 0 の必要があります。To make sure that a hexadecimal string is correctly interpreted as a positive number, the first digit in value must have a value of zero. たとえば、このメソッドは解釈0x80負の値が解釈するか、0x080または0x0080正の値として。For example, the method interprets 0x80 as a negative value, but it interprets either 0x080 or 0x0080 as a positive value. 次の例では、負と正の値を表す 16 進数の文字列間の差を示します。The following example illustrates the difference between hexadecimal strings that represent negative and positive values.

using System;
using System.Globalization;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      string[] hexStrings = { "80", "E293", "F9A2FF", "FFFFFFFF", 
                              "080", "0E293", "0F9A2FF", "0FFFFFFFF",  
                              "0080", "00E293", "00F9A2FF", "00FFFFFFFF" };
      BigInteger number = BigInteger.Zero;
                              
      foreach (string hexString in hexStrings)
      {
         if (BigInteger.TryParse(hexString, NumberStyles.AllowHexSpecifier,
                                 null, out number))
            Console.WriteLine("Converted 0x{0} to {1}.", hexString, number);
         else
            Console.WriteLine("Cannot convert '{0}' to a BigInteger.", hexString);
      }
   }
}
// The example displays the following output:
//       Converted 0x80 to -128.
//       Converted 0xE293 to -7533.
//       Converted 0xF9A2FF to -417025.
//       Converted 0xFFFFFFFF to -1.
//       Converted 0x080 to 128.
//       Converted 0x0E293 to 58003.
//       Converted 0x0F9A2FF to 16360191.
//       Converted 0x0FFFFFFFF to 4294967295.
//       Converted 0x0080 to 128.
//       Converted 0x00E293 to 58003.
//       Converted 0x00F9A2FF to 16360191.
//       Converted 0x00FFFFFFFF to 4294967295.
Imports System.Globalization
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim hexStrings() As String = { "80", "E293", "F9A2FF", "FFFFFFFF", 
                                     "080", "0E293", "0F9A2FF", "0FFFFFFFF",  
                                     "0080", "00E293", "00F9A2FF", "00FFFFFFFF" }
      Dim number As BigInteger = BigInteger.Zero
      
      For Each hexString As String In hexStrings
         If BigInteger.TryParse(hexString, NumberStyles.AllowHexSpecifier, 
                                Nothing, number) Then
            Console.WriteLine("Converted 0x{0} to {1}.", hexString, number)
         Else
            Console.WriteLine("Cannot convert '{0}' to a BigInteger.", hexString)
         End If
      Next         
   End Sub
End Module
' The example displays the following output:
'       Converted 0x80 to -128.
'       Converted 0xE293 to -7533.
'       Converted 0xF9A2FF to -417025.
'       Converted 0xFFFFFFFF to -1.
'       Converted 0x080 to 128.
'       Converted 0x0E293 to 58003.
'       Converted 0x0F9A2FF to 16360191.
'       Converted 0x0FFFFFFFF to 4294967295.
'       Converted 0x0080 to 128.
'       Converted 0x00E293 to 58003.
'       Converted 0x00F9A2FF to 16360191.
'       Converted 0x00FFFFFFFF to 4294967295.

providerパラメーターは、IFormatProvider実装します。The provider parameter is an IFormatProvider implementation. そのGetFormatメソッドを返します。 をNumberFormatInfoの書式設定に関するカルチャ固有の情報を提供するオブジェクトvalueします。Its GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of value. providerパラメーターは、次のいずれかを指定できます。The provider parameter can be any one of the following:

  • ACultureInfoの書式情報を提供するカルチャを表すオブジェクト。A CultureInfo object that represents the culture that supplies formatting information. そのGetFormatメソッドが返す、NumberFormatInfoそのカルチャの数値の書式設定情報を提供するオブジェクト。Its GetFormat method returns the NumberFormatInfo object that provides numeric formatting information for that culture.

  • ANumberFormatInfo数値書式設定情報を提供するオブジェクト。A NumberFormatInfo object that provides numeric formatting information. (その実装のGetFormat自体を返すだけです)。(Its implementation of GetFormat just returns itself.)

  • 実装するカスタム オブジェクトIFormatProviderします。A custom object that implements IFormatProvider. そのGetFormatメソッドがインスタンス化して返します、NumberFormatInfoの書式情報を提供するオブジェクト。Its GetFormat method instantiates and returns the NumberFormatInfo object that provides formatting information.

場合providernullNumberFormatInfoオブジェクトの現在のカルチャが使用されます。If provider is null, the NumberFormatInfo object for the current culture is used.

こちらもご覧ください

適用対象