BigInteger.TryParse 메서드

정의

숫자의 문자열 표현을 해당 BigInteger로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

오버로드

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

숫자의 문자열 표현을 해당 BigInteger로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

TryParse(String, IFormatProvider, BigInteger)

문자열을 값으로 구문 분석하려고 시도합니다.

TryParse(ReadOnlySpan<Char>, IFormatProvider, BigInteger)

문자 범위를 값으로 구문 분석하려고 시도합니다.

TryParse(String, BigInteger)

숫자의 문자열 표현을 해당 BigInteger로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

TryParse(ReadOnlySpan<Char>, BigInteger)

지정된 읽기 전용 문자 범위에 포함된 숫자의 표현을 해당 BigInteger로 변환해 보고, 변환에 성공했는지를 나타내는 값을 변환합니다.

TryParse(String, NumberStyles, IFormatProvider, BigInteger)

지정된 문화권별 형식과 지정된 스타일을 사용한 숫자의 문자열 표현을 해당 BigInteger로 변환해 보고, 변환에 성공했는지를 나타내는 값을 반환합니다.

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

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

숫자의 문자열 표현을 해당 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, [Runtime::InteropServices::Out] System::Numerics::BigInteger % result) = System::Numerics::INumberBase<System::Numerics::BigInteger>::TryParse;
public static bool TryParse (ReadOnlySpan<char> value, System.Globalization.NumberStyles style, IFormatProvider? provider, 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 * BigInteger -> bool
Public Shared Function TryParse (value As ReadOnlySpan(Of Char), style As NumberStyles, provider As IFormatProvider, ByRef result As BigInteger) As Boolean

매개 변수

value
ReadOnlySpan<Char>

읽기 전용 문자 범위로 나타낸 숫자 표현입니다.

style
NumberStyles

value에 나타날 수 있는 스타일 요소를 나타내는 열거형 값의 비트 조합입니다. 지정할 일반적인 값은 Integer입니다.

provider
IFormatProvider

value에 대한 문화권별 형식 지정 정보를 제공하는 개체입니다.

result
BigInteger

이 메서드가 반환되면 value에 포함된 숫자 또는 변환에 실패한 경우 BigInteger에 해당하는 Zero를 포함합니다. value 매개 변수가 빈 문자 범위이거나 style 규격의 서식이 아니면 변환에 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

value이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

예외

styleNumberStyles 값이 아닙니다.

또는

style에는 AllowHexSpecifier 또는 HexNumber 플래그가 다른 값과 함께 포함됩니다.

설명

이 오버로드는 변환이 Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) 실패할 경우 예외를 throw하지 않는다는 점을 제외하고 메서드와 같습니다. 이 메서드는 예외 처리를 사용하여 가 유효하지 않고 성공적으로 구문 분석할 수 없는 경우 value 를 테스트 FormatException 할 필요가 없습니다.

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수에 value 허용되는 스타일 요소(예: 공백 또는 양수 또는 음수 기호)를 정의합니다. 열거형의 비트 플래그 NumberStyles 조합이어야 합니다. 의 값 style에 따라 매개 변수에는 value 다음 요소가 포함될 수 있습니다.

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

매개 변수에 가 style 포함된 AllowHexSpecifier경우 매개 변수에는 value 다음 요소가 포함될 수 있습니다.

[ws] hexdigits[ws]

대괄호 ([ 및 ]) 안의 요소는 선택적 요소입니다. 다음 표에서는 각 요소에 대해 설명합니다.

요소 설명
ws 선택적 공백입니다. 플래그를 포함하는 경우 의 value 시작 부분에 공백이 표시되거나 플래그가 NumberStyles.AllowLeadingWhite 포함된 경우 stylevalue 끝에 표시할 NumberStyles.AllowTrailingWhitestyle 있습니다.
$ 문화권별 통화 기호입니다. 의 value 위치는 매개 변수의 메서드에서 반환된 NumberFormatInfo 개체의 provider 속성에 GetFormat 의해 CurrencyPositivePattern 정의됩니다. 플래그가 포함된 경우 style 통화 기호가 NumberStyles.AllowCurrencySymbolvalue 나타날 수 있습니다.
sign 선택적 기호입니다. 플래그를 포함하는 경우 의 시작 value 부분에 표시할 수 있으며 플래그가 포함된 NumberStyles.AllowTrailingSign 경우 stylevalue 끝에 표시할 수 있습니다.styleNumberStyles.AllowLeadingSign 플래그를 포함하는 NumberStyles.AllowParentheses 경우 style 괄호를 사용하여 value 음수 값을 나타낼 수 있습니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.
, 문화권별 그룹 구분 기호입니다. 에 지정된 provider 문화권의 그룹 구분 기호가 플래그를 포함하는 NumberStyles.AllowThousands 경우 stylevalue 나타날 수 있습니다.
. 문화권별 소수점 기호입니다. 에 지정된 provider 문화권의 소수점 기호는 플래그를 포함하는 NumberStyles.AllowDecimalPoint 경우 stylevalue 나타날 수 있습니다.
fractional_digits 숫자 0이 하나 이상 발생합니다. 소수 자릿수는 플래그가 포함된 NumberStyles.AllowDecimalPoint 경우에만 stylevalue 나타날 수 있습니다.
E 값이 지수(공학) 표기법으로 표시됨을 나타내는 "e" 또는 "E" 문자입니다. 매개 변수는 value 플래그를 포함하는 경우 style 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
exponential_digits 0에서 9까지의 숫자 시퀀스입니다. 매개 변수는 value 플래그를 포함하는 경우 style 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
hexdigits 0에서 f까지 또는 0부터 F까지의 16진수 숫자 시퀀스입니다.

참고

의 종결 NUL(U+0000) 문자 s 는 인수 값 style 에 관계없이 구문 분석 작업에서 무시됩니다.

비 복합 NumberStyles 숫자 외에 값에 허용되는 요소
None 10진수에만 해당합니다.
AllowDecimalPoint 소수점(.) 및 fractional_digits 요소입니다. 그러나 fractional_digits 하나 이상의 0자리 숫자로 구성되어야 하거나 메서드가 를 반환 false합니다.
AllowExponent exponential_digits 함께 지수 표기법을 나타내는 "e" 또는 "E" 문자입니다. 지수 표기법의 숫자를 나타내는 경우 value 0이 아닌 소수 구성 요소를 가질 수 없습니다.
AllowLeadingWhite 의 시작 부분에 있는 ws 요소입니다 value.
AllowTrailingWhite 의 끝에 있는 ws 요소입니다 value.
AllowLeadingSign 숫자 앞의 기호 요소 입니다.
AllowTrailingSign 숫자 뒤의 기호 요소 입니다.
AllowParentheses 숫자 값을 묶는 괄호 형식의 sign 요소입니다.
AllowThousands 그룹 구분 기호(,) 요소입니다.
AllowCurrencySymbol currency($) 요소입니다.
Currency 모든 요소. 그러나 은 value 16진수 또는 지수 표기법의 숫자를 나타낼 수 없습니다.
Float value시작 또는 끝에 있는 ws 요소는 의 value시작 부분에 서명하고 소수점(.) 기호를 표시합니다. 매개 변수는 value 지수 표기법을 사용할 수도 있습니다.
Number ws, 기호, 그룹 구분 기호(,) 및 소수점(.) 요소입니다.
Any 모든 요소. 그러나 은 value 16진수를 나타낼 수 없습니다.

플래그를 NumberStyles.AllowHexSpecifier 사용하는 value 경우 은 16진수 값이어야 합니다. 에 있을 style 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. 열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 스타일 HexNumber이 있습니다.

provider 매개 변수는 구현입니다IFormatProvider. 해당 메서드는 GetFormat 형식valueNumberFormatInfo 대한 문화권별 정보를 제공하는 개체를 반환합니다. 매개 변수는 provider 다음 중 하나일 수 있습니다.

  • CultureInfo 서식 정보를 제공하는 문화권을 나타내는 개체입니다. 해당 메서드는 GetFormat 해당 문화권에 NumberFormatInfo 대한 숫자 서식 정보를 제공하는 개체를 반환합니다.

  • NumberFormatInfo 숫자 서식 정보를 제공하는 개체입니다. (의 GetFormat 구현은 그 자체를 반환합니다.)

  • 를 구현하는 사용자 지정 개체입니다 IFormatProvider. 해당 메서드는 GetFormat 서식 정보를 제공하는 개체를 NumberFormatInfo 인스턴스화하고 반환합니다.

가 이 nullNumberFormatInfoprovider 현재 문화권의 개체가 사용됩니다.

추가 정보

적용 대상

TryParse(String, IFormatProvider, BigInteger)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

문자열을 값으로 구문 분석하려고 합니다.

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

매개 변수

s
String

구문 분석할 문자열입니다.

provider
IFormatProvider

s에 대한 문화권별 서식 정보를 제공하는 개체입니다.

result
BigInteger

이 메서드가 반환될 때 실패 시 성공적으로 구문 분석 s 한 결과 또는 정의되지 않은 값이 포함됩니다.

반환

true 가 성공적으로 구문 분석되었으면 s 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(ReadOnlySpan<Char>, IFormatProvider, BigInteger)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

문자 범위를 값으로 구문 분석하려고 합니다.

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

매개 변수

s
ReadOnlySpan<Char>

구문 분석할 문자의 범위입니다.

provider
IFormatProvider

s에 대한 문화권별 서식 정보를 제공하는 개체입니다.

result
BigInteger

이 메서드가 반환될 때 에는 성공적으로 구문 분석 s한 결과 또는 실패 시 정의되지 않은 값이 포함됩니다.

반환

true 가 성공적으로 구문 분석되었으면 s 이고, false그렇지 않으면 입니다.

적용 대상

TryParse(String, BigInteger)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

숫자의 문자열 표현을 해당 BigInteger로 변환하고, 변환에 성공했는지를 나타내는 값을 반환합니다.

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);
public static bool TryParse (string? value, out System.Numerics.BigInteger result);
static member TryParse : string * BigInteger -> bool
Public Shared Function TryParse (value As String, ByRef result As BigInteger) As Boolean

매개 변수

value
String

숫자의 문자열 표현입니다.

result
BigInteger

이 메서드가 반환되면 value에 포함된 숫자 또는 변환에 실패한 경우 0에 해당하는 BigInteger를 포함합니다. value 매개 변수가 null이거나 올바른 서식이 아니면 변환에 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

value이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

예외

value이(가) null인 경우

예제

다음 예제에서는 메서드를 TryParse(String, BigInteger) 사용하여 두 개체 BigInteger 를 인스턴스화합니다. 변환이 성공하면 각 개체를 다른 숫자로 곱한 다음 메서드를 Compare 호출하여 두 개체 간의 관계를 확인합니다.

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) 실패할 경우 예외를 throw하지 않는다는 점을 제외하고 메서드와 같습니다. 이 메서드는 가 유효하지 않고 성공적으로 구문 분석할 수 없는 경우 value 예외 처리를 사용하여 를 FormatException 테스트할 필요가 없습니다.

매개 변수는 value 다음 형식의 10진수의 문자열 표현이어야 합니다.

[ws] [기호] digits[ws]

대괄호 ([ 및 ]) 안의 요소는 선택적 요소입니다. 다음 표에서는 각 요소에 대해 설명합니다.

요소 설명
ws 선택적 공백입니다.
sign 선택적 기호입니다. 유효한 부호 문자는 현재 문화권의 NumberFormatInfo.NegativeSignNumberFormatInfo.PositiveSign 속성에 의해 결정됩니다.
숫자 0에서 9 사이의 10진수 시퀀스입니다.

참고

매개 변수에 value 지정된 문자열은 그룹 구분 기호 또는 소수 구분 기호를 포함할 수 없으며 소수 부분을 가질 수 없습니다.

매개 변수는 value 스타일을 사용하여 해석됩니다 NumberStyles.Integer . 소수 자릿수 외에도 선행 기호가 있는 선행 및 후행 공백만 허용됩니다. 에 있을 value수 있는 문화권별 서식 정보를 사용하여 스타일 요소를 명시적으로 정의하려면 메서드를 호출합니다 TryParse(String, NumberStyles, IFormatProvider, BigInteger) .

매개 변수는 value 현재 문화권에 대한 개체의 서식 정보를 NumberFormatInfo 사용하여 구문 분석됩니다. 자세한 내용은 NumberFormatInfo.CurrentInfo를 참조하세요.

이 오버로드는 매개 변수의 value 모든 숫자를 10진수로 해석합니다. 16진수의 문자열 표현을 구문 분석하려면 오버로드를 TryParse(String, NumberStyles, IFormatProvider, BigInteger) 대신 호출합니다.

추가 정보

적용 대상

TryParse(ReadOnlySpan<Char>, BigInteger)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

지정된 읽기 전용 문자 범위에 포함된 숫자의 표현을 해당 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> * BigInteger -> bool
Public Shared Function TryParse (value As ReadOnlySpan(Of Char), ByRef result As BigInteger) As Boolean

매개 변수

value
ReadOnlySpan<Char>

읽기 전용 문자 범위로 나타낸 숫자 표현입니다.

result
BigInteger

이 메서드가 반환되면 value에 포함된 숫자 또는 변환에 실패한 경우 0에 해당하는 BigInteger를 포함합니다. value 매개 변수가 빈 문자 범위이거나 올바른 서식이 아니면 변환에 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

value이(가) 성공적으로 변환되었으면 true이고, 그렇지 않으면 false입니다.

추가 정보

적용 대상

TryParse(String, NumberStyles, IFormatProvider, BigInteger)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

지정된 문화권별 형식과 지정된 스타일을 사용한 숫자의 문자열 표현을 해당 BigInteger로 변환해 보고, 변환에 성공했는지를 나타내는 값을 반환합니다.

public:
 static bool TryParse(System::String ^ value, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Numerics::BigInteger % result);
public:
 static bool TryParse(System::String ^ value, System::Globalization::NumberStyles style, IFormatProvider ^ provider, [Runtime::InteropServices::Out] System::Numerics::BigInteger % result) = System::Numerics::INumberBase<System::Numerics::BigInteger>::TryParse;
public static bool TryParse (string value, System.Globalization.NumberStyles style, IFormatProvider provider, 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 * BigInteger -> bool
Public Shared Function TryParse (value As String, style As NumberStyles, provider As IFormatProvider, ByRef result As BigInteger) As Boolean

매개 변수

value
String

숫자의 문자열 표현입니다. 이 문자열은 style이 지정하는 스타일을 사용하여 해석됩니다.

style
NumberStyles

value에 나타날 수 있는 스타일 요소를 나타내는 열거형 값의 비트 조합입니다. 지정할 일반적인 값은 Integer입니다.

provider
IFormatProvider

value에 대한 문화권별 형식 지정 정보를 제공하는 개체입니다.

result
BigInteger

이 메서드가 반환되면 value에 포함된 숫자 또는 변환에 실패한 경우 BigInteger에 해당하는 Zero를 포함합니다. value 매개 변수가 null이거나 style과 호환되지 않는 서식으로 되어 있으면 변환에 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다.

반환

true 매개 변수가 변환되었으면 value이고, 그렇지 않으면 false입니다.

예외

styleNumberStyles 값이 아닙니다.

또는

style에는 AllowHexSpecifier 또는 HexNumber 플래그가 다른 값과 함께 포함됩니다.

예제

다음 예제에서는 및 매개 변수에 TryParse(String, NumberStyles, IFormatProvider, BigInteger) 대 한 값의 다양 한 조합을 사용 하 여 메서드를 styleprovider 호출 합니다.

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 클래스의 instance 전달합니다. 이 클래스는 타일(~)을 음수 기호로 정의합니다.

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) 실패할 경우 예외를 throw하지 않는다는 점을 제외하고 메서드와 같습니다. 이 메서드는 가 유효하지 않고 성공적으로 구문 분석할 수 없는 경우 value 예외 처리를 사용하여 를 테스트 FormatException 할 필요가 없습니다.

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수에 value 허용되는 스타일 요소(예: 공백 또는 양수 또는 음수 기호)를 정의합니다. 열거형의 비트 플래그 NumberStyles 조합이어야 합니다. 의 값 style에 따라 매개 변수에 value 다음 요소가 포함될 수 있습니다.

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

매개 변수에 가 style 포함된 AllowHexSpecifier경우 매개 변수에는 value 다음 요소가 포함될 수 있습니다.

[ws] hexdigits[ws]

대괄호 ([ 및 ]) 안의 요소는 선택적 요소입니다. 다음 표에서는 각 요소에 대해 설명합니다.

요소 설명
ws 선택적 공백입니다. 플래그를 포함하는 경우 의 value 시작 부분에 공백이 표시되거나 플래그가 NumberStyles.AllowLeadingWhite 포함된 경우 stylevalue 끝에 공백이 NumberStyles.AllowTrailingWhite 표시될 수 style 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 위치는 매개 변수의 메서드 provider 에서 반환된 NumberFormatInfo 개체의 속성에 GetFormat 의해 CurrencyPositivePattern 정의됩니다. 플래그가 포함된 경우 style 통화 기호가 NumberStyles.AllowCurrencySymbolvalue 나타날 수 있습니다.
sign 선택적 기호입니다. 플래그가 포함된 경우 의 시작 value 부분에 기호가 NumberStyles.AllowLeadingSign 표시되고 플래그가 포함된 NumberStyles.AllowTrailingSign 경우 stylevalue 끝에 표시할 수 style 있습니다. 플래그가 포함된 NumberStyles.AllowParentheses 경우 style 괄호를 사용하여 value 음수 값을 나타낼 수 있습니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.
, 문화권별 그룹 구분 기호입니다. 에 지정된 provider 문화권의 그룹 구분 기호가 플래그를 포함하는 NumberStyles.AllowThousands 경우 stylevalue 나타날 수 있습니다.
. 문화권별 소수점 기호입니다. 에 지정된 provider 문화권의 소수점 기호가 플래그를 포함하는 NumberStyles.AllowDecimalPoint 경우 stylevalue 나타날 수 있습니다.
fractional_digits 숫자 0이 하나 이상 발생합니다. 소수 자릿수는 플래그가 포함된 경우에만 stylevalue 표시할 NumberStyles.AllowDecimalPoint 수 있습니다.
E 값이 지수(과학적) 표기법으로 표시됨을 나타내는 "e" 또는 "E" 문자입니다. 플래그가 포함된 경우 style 매개 변수는 value 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
exponential_digits 0에서 9까지의 숫자 시퀀스입니다. 매개 변수는 value 플래그를 포함하는 경우 style 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
hexdigits 0에서 f까지 또는 0부터 F까지의 16진수 숫자 시퀀스입니다.

참고

의 종결 NUL(U+0000) 문자 s 는 인수 값 style 에 관계없이 구문 분석 작업에서 무시됩니다.

10진수만 있는 문자열(플래그에 NumberStyles.None 해당)은 항상 성공적으로 구문 분석됩니다. 나머지 NumberStyles 멤버의 대부분은 이 입력 문자열에 존재할 수 있지만 존재할 필요는 없는 요소를 제어합니다. 다음 표에서는 개별 NumberStyles 멤버가 에 value있을 수 있는 요소에 미치는 영향을 나타냅니다.

비 복합 NumberStyles 숫자 외에 값에 허용되는 요소
None 10진수에만 해당합니다.
AllowDecimalPoint 소수점(.) 및 fractional_digits 요소입니다. 그러나 fractional_digits 하나 이상의 0자리 숫자로 구성되어야 하거나 메서드가 를 반환 false합니다.
AllowExponent exponential_digits 함께 지수 표기법을 나타내는 "e" 또는 "E" 문자입니다. 지수 표기법의 숫자를 나타내는 경우 value 0이 아닌 소수 구성 요소를 가질 수 없습니다.
AllowLeadingWhite 의 시작 부분에 있는 ws 요소입니다 value.
AllowTrailingWhite 의 끝에 있는 ws 요소입니다 value.
AllowLeadingSign 숫자 앞의 기호 요소 입니다.
AllowTrailingSign 숫자 뒤의 기호 요소 입니다.
AllowParentheses 숫자 값을 묶는 괄호 형식의 sign 요소입니다.
AllowThousands 그룹 구분 기호(,) 요소입니다.
AllowCurrencySymbol currency($) 요소입니다.
Currency 모든 요소. 그러나 은 value 16진수 또는 지수 표기법의 숫자를 나타낼 수 없습니다.
Float value시작 또는 끝에 있는 ws 요소는 의 value시작 부분에 서명하고 소수점(.) 기호를 표시합니다. 매개 변수는 value 지수 표기법을 사용할 수도 있습니다.
Number ws, 기호, 그룹 구분 기호(,) 및 소수점(.) 요소입니다.
Any 모든 요소. 그러나 은 value 16진수를 나타낼 수 없습니다.

중요

메서드를 사용하여 메서드에서 TryParse 출력 ToString 한 값의 문자열 표현을 BigInteger 왕복하는 경우 메서드를 "R" 형식 지정자와 함께 사용하여 BigInteger.ToString(String) 값의 BigInteger 문자열 표현을 생성해야 합니다. 그렇지 않으면 의 문자열 표현은 원래 값의 BigInteger 가장 중요한 숫자 50개만 유지하며 메서드를 사용하여 TryParse 값을 복원 BigInteger 할 때 데이터가 손실될 수 있습니다.

플래그를 NumberStyles.AllowHexSpecifier 사용하는 value 경우 은 16진수 값이어야 합니다. 에 있을 style 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. 열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 스타일 HexNumber이 있습니다.

참고

가 16진수의 문자열 표현인 경우 value 16진수로 구분하는 장식(예: 0x 또는 &h)이 앞에 올 수 없습니다. 이렇게 하면 변환이 실패합니다.

가 16진수 문자열인 경우 value 메서드는 처음 두 개의 16진수가 보다 크거나 같은 경우 두 개의 보수 표현을 사용하여 저장된 음수로 0x80해석 value 합니다.TryParse(String, NumberStyles, IFormatProvider, BigInteger) 즉, 메서드는 의 첫 번째 바이트 value 에서 가장 높은 순서의 비트를 부호 비트로 해석합니다. 16진수 문자열이 양수로 올바르게 해석되도록 하려면 의 value 첫 번째 숫자 값이 0이어야 합니다. 예를 들어 메서드는 음수 0x80 값으로 해석하지만 또는 0x0080 를 양수 값으로 해석합니다0x080. 다음 예제에서는 음수 및 양수 값을 나타내는 16진수 문자열 간의 차이점을 보여 줍니다.

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. 해당 메서드는 GetFormat 형식valueNumberFormatInfo 대한 문화권별 정보를 제공하는 개체를 반환합니다. 매개 변수는 provider 다음 중 하나일 수 있습니다.

  • CultureInfo 서식 정보를 제공하는 문화권을 나타내는 개체입니다. 해당 메서드는 GetFormat 해당 문화권에 NumberFormatInfo 대한 숫자 서식 정보를 제공하는 개체를 반환합니다.

  • NumberFormatInfo 숫자 서식 정보를 제공하는 개체입니다. (의 GetFormat 구현은 그 자체를 반환합니다.)

  • 를 구현하는 사용자 지정 개체입니다 IFormatProvider. 해당 메서드는 GetFormat 서식 정보를 제공하는 개체를 NumberFormatInfo 인스턴스화하고 반환합니다.

가 이 nullNumberFormatInfoprovider 현재 문화권의 개체가 사용됩니다.

추가 정보

적용 대상