BigInteger.Parse 메서드

정의

숫자의 문자열 표현을 해당하는 BigInteger로 변환합니다.

오버로드

Parse(String)

숫자의 문자열 표현을 해당하는 BigInteger로 변환합니다.

Parse(ReadOnlySpan<Char>, IFormatProvider)

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

Parse(String, NumberStyles)

숫자를 지정된 스타일로 나타낸 문자열 표현을 해당 BigInteger로 변환합니다.

Parse(String, IFormatProvider)

숫자를 지정된 문화권별 형식으로 나타낸 문자열 표현을 해당 BigInteger로 변환합니다.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

지정된 읽기 전용 문자 범위에 포함된 지정된 스타일의 숫자 표현을 해당하는 BigInteger로 변환합니다.

Parse(String, NumberStyles, IFormatProvider)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 BigInteger로 변환합니다.

Parse(String)

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

숫자의 문자열 표현을 해당하는 BigInteger로 변환합니다.

public:
 static System::Numerics::BigInteger Parse(System::String ^ value);
public static System.Numerics.BigInteger Parse (string value);
static member Parse : string -> System.Numerics.BigInteger
Public Shared Function Parse (value As String) As BigInteger

매개 변수

value
String

변환할 숫자가 포함된 문자열입니다.

반환

value 매개 변수에 지정된 숫자에 해당하는 값입니다.

예외

value이(가) null인 경우

value가 올바른 형식이 아닙니다.

예제

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

string stringToParse = String.Empty;
try
{
   // Parse two strings.
   string string1, string2;
   string1 = "12347534159895123";
   string2 = "987654321357159852";
   stringToParse = string1;
   BigInteger number1 = BigInteger.Parse(stringToParse);
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number1);
   stringToParse = string2;
   BigInteger number2 = BigInteger.Parse(stringToParse);
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number2);
   // Perform arithmetic operations on the two numbers.
   number1 *= 3;
   number2 *= 2;
   // Compare the numbers.
   int result = BigInteger.Compare(number1, number2);
   switch (result)
   {
      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;
   }
}
catch (FormatException)
{
   Console.WriteLine("Unable to parse {0}.", stringToParse);
}
// The example displays the following output:
//    Converted '12347534159895123' to 12,347,534,159,895,123.
//    Converted '987654321357159852' to 987,654,321,357,159,852.
//    1975308642714319704 is greater than 37042602479685369.
Dim stringToParse As String = String.Empty
Try
   ' Parse two strings.
   Dim string1, string2 As String
   string1 = "12347534159895123"
   string2 = "987654321357159852"
   stringToParse = string1
   Dim number1 As BigInteger = BigInteger.Parse(stringToParse)
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number1)
   stringToParse = string2
   Dim number2 As BigInteger = BigInteger.Parse(stringToParse)
   Console.WriteLine("Converted '{0}' to {1:N0}.", stringToParse, number2)
   ' Perform arithmetic operations on the two numbers.
   number1 *= 3
   number2 *= 2
   ' Compare the numbers.
   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      
Catch e As FormatException
   Console.WriteLine("Unable to parse {0}.", stringToParse)
End Try
' The example displays the following output:
'    Converted '12347534159895123' to 12,347,534,159,895,123.
'    Converted '987654321357159852' to 987,654,321,357,159,852.
'    1975308642714319704 is greater than 37042602479685369.

설명

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

[ws] [sign] digits[ws]

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

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

참고

매개 변수로 value 지정된 문자열은 스타일을 사용하여 해석됩니다 NumberStyles.Integer . 그룹 구분 기호 또는 10진수 구분 기호를 포함할 수 없으며 소수 부분을 가질 수 없습니다.

매개 변수는 value 현재 시스템 문화권에 대해 초기화된 개체의 System.Globalization.NumberFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 자세한 내용은 NumberFormatInfo.CurrentInfo를 참조하세요. 특정 문화권의 서식 정보를 사용하여 문자열을 구문 분석하려면 메서드를 Parse(String, IFormatProvider) 사용합니다.

중요

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

추가 정보

적용 대상

Parse(ReadOnlySpan<Char>, IFormatProvider)

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

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

public:
 static System::Numerics::BigInteger Parse(ReadOnlySpan<char> s, IFormatProvider ^ provider) = ISpanParsable<System::Numerics::BigInteger>::Parse;
public static System.Numerics.BigInteger Parse (ReadOnlySpan<char> s, IFormatProvider? provider);
static member Parse : ReadOnlySpan<char> * IFormatProvider -> System.Numerics.BigInteger
Public Shared Function Parse (s As ReadOnlySpan(Of Char), provider As IFormatProvider) As BigInteger

매개 변수

s
ReadOnlySpan<Char>

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

provider
IFormatProvider

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

반환

구문 분석의 결과입니다 s.

구현

적용 대상

Parse(String, NumberStyles)

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

숫자를 지정된 스타일로 나타낸 문자열 표현을 해당 BigInteger로 변환합니다.

public:
 static System::Numerics::BigInteger Parse(System::String ^ value, System::Globalization::NumberStyles style);
public static System.Numerics.BigInteger Parse (string value, System.Globalization.NumberStyles style);
static member Parse : string * System.Globalization.NumberStyles -> System.Numerics.BigInteger
Public Shared Function Parse (value As String, style As NumberStyles) As BigInteger

매개 변수

value
String

변환할 숫자가 포함된 문자열입니다.

style
NumberStyles

value에 사용할 수 있는 서식을 지정하는 열거형 값의 비트 조합입니다.

반환

value 매개 변수에 지정된 숫자에 해당하는 값입니다.

예외

styleNumberStyles 값이 아닙니다.

또는

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

value이(가) null인 경우

valueNumberStyles에 의해 지정된 입력 패턴에 맞지 않습니다.

예제

다음 예제에서는 매개 변수에 대 한 Parse(String, NumberStyles) 몇 가지 가능한 값을 사용 하는 메서드에 대 한 호출을 보여 줍니다 style . 문자열을 16진수 값으로 해석하는 방법과 공백 및 기호를 허용하지 않는 방법을 보여 줍니다.

BigInteger number;
// Method should succeed (white space and sign allowed)
number = BigInteger.Parse("   -68054   ", NumberStyles.Integer);
Console.WriteLine(number);
// Method should succeed (string interpreted as hexadecimal)
number = BigInteger.Parse("68054", NumberStyles.AllowHexSpecifier);
Console.WriteLine(number);
// Method call should fail: sign not allowed
try
{
   number = BigInteger.Parse("   -68054  ", NumberStyles.AllowLeadingWhite
                                            | NumberStyles.AllowTrailingWhite);
   Console.WriteLine(number);
}
catch (FormatException e)
{
   Console.WriteLine(e.Message);
}
// Method call should fail: white space not allowed
try
{
   number = BigInteger.Parse("   68054  ", NumberStyles.AllowLeadingSign);
   Console.WriteLine(number);
}
catch (FormatException e)
{
   Console.WriteLine(e.Message);
}
//
// The method produces the following output:
//
//     -68054
//     426068
//     Input string was not in a correct format.
//     Input string was not in a correct format.
Dim number As BigInteger 
' Method should succeed (white space and sign allowed)
number = BigInteger.Parse("   -68054   ", NumberStyles.Integer)
Console.WriteLine(number)
' Method should succeed (string interpreted as hexadecimal)
number = BigInteger.Parse("68054", NumberStyles.AllowHexSpecifier)
Console.WriteLine(number)
' Method call should fail: sign not allowed
Try
   number = BigInteger.Parse("   -68054  ", NumberStyles.AllowLeadingWhite _
                                            Or NumberStyles.AllowTrailingWhite)
   Console.WriteLine(number)
Catch e As FormatException
   Console.WriteLine(e.Message)
End Try                                                     
' Method call should fail: white space not allowed
Try
   number = BigInteger.Parse("   68054  ", NumberStyles.AllowLeadingSign)
   Console.WriteLine(number)
Catch e As FormatException
   Console.WriteLine(e.Message)
End Try    
'
' The method produces the following output:
'
'     -68054
'     426068
'     Input string was not in a correct format.
'     Input string was not in a correct format.

설명

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수에 허용되는 value 스타일 요소(예: 공백, 양수 또는 음수 기호, 그룹 구분 기호 또는 소수점 기호)를 정의합니다. styles 는 열거형의 비트 플래그 NumberStyles 조합이어야 합니다. 매개 변수는 style 16진수 값의 문자열 표현을 포함하는 경우 value , 가 나타내는 value 숫자 시스템(10진수 또는 16진수)이 런타임에만 알려지거나 에서 value공백 또는 기호 기호를 허용하지 않으려는 경우에 이 메서드 오버로드를 유용하게 만듭니다.

의 값 style에 따라 매개 변수에는 value 다음 요소가 포함될 수 있습니다.

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

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

[ws] hexdigits[ws]

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

요소 설명
ws 선택적 공백입니다. 플래그를 포함하는 경우 의 시작 value 부분에 공백이 NumberStyles.AllowLeadingWhite 나타날 수 있으며 플래그가 포함된 NumberStyles.AllowTrailingWhite 경우 stylevalue 끝에 표시할 수 style 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 위치는 현재 문화권의 NumberFormatInfo.CurrencyNegativePatternNumberFormatInfo.CurrencyPositivePattern 속성에 의해 정의됩니다. 플래그가 포함된 경우 style 현재 문화권의 통화 기호가 NumberStyles.AllowCurrencySymbolvalue 나타날 수 있습니다.
sign 선택적 기호입니다. 플래그를 포함하는 경우 의 시작 value 부분에 표시할 수 있으며 플래그가 포함된 NumberStyles.AllowTrailingSign 경우 stylevalue 끝에 표시할 수 있습니다.styleNumberStyles.AllowLeadingSign 플래그를 포함하는 NumberStyles.AllowParentheses 경우 style 괄호를 사용하여 value 음수 값을 나타낼 수 있습니다.
숫자

fractional_digits

exponential_digits
0에서 9까지의 숫자 시퀀스입니다. fractional_digits 경우 숫자 0만 유효합니다.
, 문화권별 그룹 구분 기호입니다. 플래그가 포함된 경우 style 현재 문화권의 그룹 구분 기호가 NumberStyles.AllowThousandsvalue 나타날 수 있습니다.
. 문화권별 소수점 기호입니다. 플래그가 포함된 경우 style 현재 문화권의 소수점 기호가 NumberStyles.AllowDecimalPointvalue 나타날 수 있습니다. 구문 분석 작업이 성공하려면 숫자 0만 소수 자릿수로 표시할 수 있습니다. fractional_digits 다른 숫자가 포함되어 있으면 이 FormatException throw됩니다.
E 값이 지수(공학) 표기법으로 표시됨을 나타내는 "e" 또는 "E" 문자입니다. 매개 변수는 value 플래그를 포함하는 경우 style 지수 표기법의 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
hexdigits 0에서 f까지 또는 0부터 F까지의 16진수 숫자 시퀀스입니다.

참고

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

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

NumberStyles 숫자 외에 에서 value 허용되는 요소
None digits 요소만 해당합니다.
AllowDecimalPoint 소수점(.) 및 소수 자릿수 요소입니다 .
AllowExponent exponential_digits 함께 지수 표기법을 나타내는 "e" 또는 "E" 문자입니다.
AllowLeadingWhite 의 시작 부분에 있는 ws 요소입니다 value.
AllowTrailingWhite 의 끝에 있는 ws 요소입니다 value.
AllowLeadingSign 의 시작 부분에 있는 기호 요소입니다 value.
AllowTrailingSign 의 끝에 있는 기호 요소입니다 value.
AllowParentheses 숫자 값을 묶는 괄호 형식의 기호 요소입니다.
AllowThousands 그룹 구분 기호(,) 요소입니다.
AllowCurrencySymbol 통화($) 요소입니다.
Currency 모든 요소. 그러나 는 value 16진수 또는 지수 표기법으로 숫자를 나타낼 수 없습니다.
Float 의 시작 또는 끝에 value있는 ws 요소, 의 value시작 부분에 기호, 소수점(.) 기호입니다. 매개 변수는 value 지수 표기법을 사용할 수도 있습니다.
Number , , 그룹 구분 기호(,) 및 소수점(.) 요소입니다. signws
Any 모든 요소. 그러나 은 value 16진수를 나타낼 수 없습니다.

중요

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

에 특정 스타일 요소를 valueNumberStyles.AllowHexSpecifier 허용하지만 필요하지 않은 다른 NumberStyles 값과 달리 스타일 값은 의 개별 숫자 문자가 항상 16진수 문자 value 로 해석됨을 의미합니다. 유효한 16진수 문자는 0-9, A-F 및 a-f입니다. 매개 변수와 style 결합할 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. (열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 숫자 스타일 HexNumber가 포함됩니다.)

참고

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

가 16진수 문자열인 경우 value 메서드는 처음 두 개의 16진수가 보다 크거나 같은 경우 두 개의 보수 표현을 사용하여 저장된 음수로 0x80해석 value 합니다.Parse(String, NumberStyles) 즉, 메서드는 의 첫 번째 바이트 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" };
      foreach (string hexString in hexStrings)
      {
         BigInteger number = BigInteger.Parse(hexString, NumberStyles.AllowHexSpecifier);
         Console.WriteLine("Converted 0x{0} to {1}.", hexString, number);
      }
   }
}
// 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" }
      For Each hexString As String In hexStrings
         Dim number As BigInteger = BigInteger.Parse(hexString, NumberStyles.AllowHexSpecifier)
         Console.WriteLine("Converted 0x{0} to {1}.", hexString, number)
      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.

매개 변수는 value 현재 시스템 문화권에 대해 초기화된 개체의 NumberFormatInfo 서식 정보를 사용하여 구문 분석됩니다. 구문 분석 작업에 서식 정보가 사용되는 문화권을 지정하려면 오버로드를 호출합니다 Parse(String, NumberStyles, IFormatProvider) .

추가 정보

적용 대상

Parse(String, IFormatProvider)

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

숫자를 지정된 문화권별 형식으로 나타낸 문자열 표현을 해당 BigInteger로 변환합니다.

public:
 static System::Numerics::BigInteger Parse(System::String ^ value, IFormatProvider ^ provider);
public:
 static System::Numerics::BigInteger Parse(System::String ^ value, IFormatProvider ^ provider) = IParsable<System::Numerics::BigInteger>::Parse;
public static System.Numerics.BigInteger Parse (string value, IFormatProvider provider);
public static System.Numerics.BigInteger Parse (string value, IFormatProvider? provider);
static member Parse : string * IFormatProvider -> System.Numerics.BigInteger
Public Shared Function Parse (value As String, provider As IFormatProvider) As BigInteger

매개 변수

value
String

변환할 숫자가 포함된 문자열입니다.

provider
IFormatProvider

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

반환

value 매개 변수에 지정된 숫자에 해당하는 값입니다.

구현

예외

value이(가) null인 경우

value가 올바른 형식이 아닙니다.

예제

다음 예제에서는 서식 값에 대한 BigInteger 음수 기호로 타일(~)을 정의하는 두 가지 방법을 보여 줍니다. 원래 문자열과 BigInteger 동일한 형식으로 값을 표시하려면 코드에서 메서드를 BigInteger.ToString(IFormatProvider) 호출하고 서식 정보를 제공하는 개체를 NumberFormatInfo 전달해야 합니다.

첫 번째 예제에서는 구현 IFormatProvider 하는 클래스를 정의 하 고 형식 지정 정보를 제공 하는 개체를 NumberFormatInfo 반환 하는 메서드를 사용 합니다GetFormat.

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

BigInteger 그런 다음, 다음 코드로 개체를 인스턴스화할 수 있습니다.

BigInteger number = BigInteger.Parse("~6354129876", new BigIntegerFormatProvider());
// Display value using same formatting information
Console.WriteLine(number.ToString(new BigIntegerFormatProvider()));
// Display value using formatting of current culture
Console.WriteLine(number);
Dim number As BigInteger = BigInteger.Parse("~6354129876", New BigIntegerFormatProvider)
' Display value using same formatting information
Console.WriteLine(number.ToString(New BigIntegerFormatProvider))
' Display value using formatting of current culture
Console.WriteLine(number)

두 번째 예제는 더 간단합니다. 매개 변수에 NumberFormatInfo 서식 정보를 제공하는 개체를 provider 전달합니다.

NumberFormatInfo fmt = new NumberFormatInfo();
fmt.NegativeSign = "~";

BigInteger number = BigInteger.Parse("~6354129876", fmt);
// Display value using same formatting information
Console.WriteLine(number.ToString(fmt));
// Display value using formatting of current culture
Console.WriteLine(number);
Dim fmt As New NumberFormatInfo()
fmt.NegativeSign = "~"

Dim number As BigInteger = BigInteger.Parse("~6354129876", fmt)
' Display value using same formatting information
Console.WriteLine(number.ToString(fmt))
' Display value using formatting of current culture
Console.WriteLine(number)

설명

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

[ws] [기호] digits[ws]

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

요소 설명
ws 선택적 공백입니다.
sign 선택적 기호입니다. 유효한 기호 문자는 개체의 메서드에서 NumberFormatInfo.NegativeSign 반환되는 개체의 NumberFormatInfoNumberFormatInfo.PositiveSign 속성에 providerGetFormat 의해 결정됩니다.
숫자 0에서 9 사이의 숫자 시퀀스입니다. 선행 0은 무시됩니다.

참고

매개 변수에 지정된 value 문자열은 스타일을 사용하여 NumberStyles.Integer 해석됩니다. 그룹 구분 기호 또는 10진수 구분 기호를 포함할 수 없으며 소수 부분을 포함할 수 없습니다.

중요

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

provider 매개 변수는 메서드가 IFormatProviderGetFormat 문화권별 서식 지정 정보를 제공하는 개체를 NumberFormatInfo 반환하는 구현입니다. 메서드가 Parse(String, IFormatProvider) 호출되면 매개 변수의 GetFormat 메서드를 provider 호출하고 형식을 나타내는 개체로 Type 전달합니다NumberFormatInfo. 그런 다음 메서드는 GetFormat 매개 변수의 형식에 대한 정보를 제공하는 개체를 반환 NumberFormatInfo 합니다 value . 매개 변수를 사용하여 provider 구문 분석 작업에 사용자 지정 서식 정보를 제공하는 세 가지 방법이 있습니다.

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

  • 숫자 서식 정보를 제공하는 실제 NumberFormatInfo 개체를 전달할 수 있습니다. (의 구현은 GetFormat 그 자체를 반환합니다.)

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

가 이nullprovider 의 서식 value 은 현재 문화권의 개체에 NumberFormatInfo 따라 해석됩니다.

추가 정보

적용 대상

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

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

지정된 읽기 전용 문자 범위에 포함된 지정된 스타일의 숫자 표현을 해당하는 BigInteger로 변환합니다.

public static System.Numerics.BigInteger Parse (ReadOnlySpan<char> value, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
public static System.Numerics.BigInteger Parse (ReadOnlySpan<char> value, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> System.Numerics.BigInteger
Public Shared Function Parse (value As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As BigInteger

매개 변수

value
ReadOnlySpan<Char>

변환할 번호가 포함된 문자의 읽기 전용 범위입니다.

style
NumberStyles

value에 사용할 수 있는 서식을 지정하는 열거형 값의 비트 조합입니다.

provider
IFormatProvider

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

반환

value 매개 변수에 지정된 숫자에 해당하는 값입니다.

구현

예외

styleNumberStyles 값이 아닙니다.

또는

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

value이(가) null인 경우

valuestyle에 의해 지정된 입력 패턴에 맞지 않습니다.

설명

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수에 허용되는 value 스타일 요소(예: 공백, 양수 또는 음수 기호, 그룹 구분 기호 또는 소수점 기호)를 정의합니다. styles 는 열거형의 비트 플래그 NumberStyles 조합이어야 합니다. 매개 변수는 style 이 메서드 오버로드가 16진수 값의 표현을 포함하는 경우 value , 가 나타내는 value 숫자 시스템(10진수 또는 16진수)이 런타임에만 알려지거나 에서 value공백 또는 기호 기호를 허용하지 않으려는 경우에 유용합니다.

의 값 style에 따라 매개 변수에 value 다음 요소가 포함될 수 있습니다.

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

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

[ws] hexdigits[ws]

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

요소 설명
ws 선택적 공백입니다. 플래그가 포함된 경우 의 시작 value 부분에 공백이 NumberStyles.AllowLeadingWhite 표시될 수 있으며 플래그가 포함된 NumberStyles.AllowTrailingWhite 경우 stylevalue 끝에 표시될 수 style 있습니다.
$ 문화권별 통화 기호입니다. 의 value 위치는 매개 변수로 NumberFormatInfo.CurrencyNegativePattern 표시된 문화권의 및 NumberFormatInfo.CurrencyPositivePattern 속성에 의해 provider 정의됩니다. 플래그가 포함된 경우 style 현재 문화권의 통화 기호가 NumberStyles.AllowCurrencySymbolvalue 나타날 수 있습니다.
sign 선택적 기호입니다. 플래그가 포함된 경우 의 시작 value 부분에 기호가 NumberStyles.AllowLeadingSign 표시되고 플래그가 포함된 NumberStyles.AllowTrailingSign 경우 stylevalue 끝에 표시할 수 style 있습니다. 플래그가 포함된 NumberStyles.AllowParentheses 경우 style 괄호를 사용하여 value 음수 값을 나타낼 수 있습니다.
숫자

fractional_digits

exponential_digits
0에서 9까지의 숫자 시퀀스입니다. fractional_digits 경우 숫자 0만 유효합니다.
, 문화권별 그룹 구분 기호입니다. 에 지정된 provider 문화권의 그룹 구분 기호가 플래그를 포함하는 NumberStyles.AllowThousands 경우 stylevalue 나타날 수 있습니다.
. 문화권별 소수점 기호입니다. 에 지정된 provider 문화권의 소수점 기호는 플래그가 포함된 NumberStyles.AllowDecimalPoint 경우 stylevalue 나타날 수 있습니다. 구문 분석 작업이 성공하려면 숫자 0만 소수 자릿수로 표시할 수 있습니다. fractional_digits 다른 숫자가 포함되어 있으면 이 FormatException throw됩니다.
E 값이 지수(과학적) 표기법으로 표시됨을 나타내는 "e" 또는 "E" 문자입니다. 플래그가 포함된 경우 style 매개 변수는 value 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
hexdigits 0에서 f까지 또는 0부터 F까지의 16진수 숫자 시퀀스입니다.

참고

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

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

NumberStyles 값 숫자 외에 값에 허용되는 요소
None digits 요소만 해당합니다.
AllowDecimalPoint 소수점(.) 및 소수 자릿수 요소입니다 .
AllowExponent 지수 표기법을 나타내는 "e" 또는 "E" 문자입니다. exponential_digits 함께.
AllowLeadingWhite 의 시작 부분에 있는 ws 요소입니다 value.
AllowTrailingWhite 의 끝에 있는 ws 요소입니다 value.
AllowLeadingSign 의 시작 부분에 있는 기호 요소입니다 value.
AllowTrailingSign 의 끝에 있는 기호 요소입니다 value.
AllowParentheses 숫자 값을 묶는 괄호 형식의 기호 요소입니다.
AllowThousands 그룹 구분 기호(,) 요소입니다.
AllowCurrencySymbol 통화($) 요소입니다.
Currency 모든 요소. 그러나 는 value 16진수 또는 지수 표기법으로 숫자를 나타낼 수 없습니다.
Float value 시작 또는 끝 부분에 있는 ws 요소,의 시작 부분에 있는 기호 및 소수점 (.) 기호를 지정 합니다. value 매개 변수는 value 지수 표기법을 사용할 수도 있습니다.
Number ws, sign, 그룹 구분 기호(,) 및 소수점(.) 요소입니다.
Any 모든 요소. 그러나 은 value 16진수를 나타낼 수 없습니다.

에서 특정 스타일 요소를 valueNumberStyles.AllowHexSpecifier 허용하지만 필요하지 않은 다른 NumberStyles 값과 달리 스타일 값은 의 개별 숫자 문자가 항상 16진수 문자 value 로 해석됨을 의미합니다. 유효한 16진수 문자는 0-9, A-F 및 a-f입니다. 매개 변수와 style 결합할 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. (열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 숫자 스타일 HexNumber가 포함됩니다.)

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

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

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

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

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

추가 정보

적용 대상

Parse(String, NumberStyles, IFormatProvider)

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

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 BigInteger로 변환합니다.

public:
 static System::Numerics::BigInteger Parse(System::String ^ value, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public:
 static System::Numerics::BigInteger Parse(System::String ^ value, System::Globalization::NumberStyles style, IFormatProvider ^ provider) = System::Numerics::INumberBase<System::Numerics::BigInteger>::Parse;
public static System.Numerics.BigInteger Parse (string value, System.Globalization.NumberStyles style, IFormatProvider provider);
public static System.Numerics.BigInteger Parse (string value, System.Globalization.NumberStyles style, IFormatProvider? provider);
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> System.Numerics.BigInteger
Public Shared Function Parse (value As String, style As NumberStyles, provider As IFormatProvider) As BigInteger

매개 변수

value
String

변환할 숫자가 포함된 문자열입니다.

style
NumberStyles

value에 사용할 수 있는 서식을 지정하는 열거형 값의 비트 조합입니다.

provider
IFormatProvider

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

반환

value 매개 변수에 지정된 숫자에 해당하는 값입니다.

구현

예외

styleNumberStyles 값이 아닙니다.

또는

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

value이(가) null인 경우

valuestyle에 의해 지정된 입력 패턴에 맞지 않습니다.

예제

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

// Call parse with default values of style and provider
Console.WriteLine(BigInteger.Parse("  -300   ",
                  NumberStyles.Integer, CultureInfo.CurrentCulture));
// Call parse with default values of style and provider supporting tilde as negative sign
Console.WriteLine(BigInteger.Parse("   ~300  ",
                                   NumberStyles.Integer, new BigIntegerFormatProvider()));
// Call parse with only AllowLeadingWhite and AllowTrailingWhite
// Exception thrown because of presence of negative sign
try
{
   Console.WriteLine(BigInteger.Parse("    ~300   ",
                                NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite,
                                new BigIntegerFormatProvider()));
}
catch (FormatException e)
{
   Console.WriteLine("{0}: \n   {1}", e.GetType().Name, e.Message);
}
// Call parse with only AllowHexSpecifier
// Exception thrown because of presence of negative sign
try
{
   Console.WriteLine(BigInteger.Parse("-3af", NumberStyles.AllowHexSpecifier,
                                      new BigIntegerFormatProvider()));
}
catch (FormatException e)
{
   Console.WriteLine("{0}: \n   {1}", e.GetType().Name, e.Message);
}
// Call parse with only NumberStyles.None
// Exception thrown because of presence of white space and sign
try
{
   Console.WriteLine(BigInteger.Parse(" -300 ", NumberStyles.None,
                                      new BigIntegerFormatProvider()));
}
catch (FormatException e)
{
   Console.WriteLine("{0}: \n   {1}", e.GetType().Name, e.Message);
}
// The example displays the followingoutput:
//       -300
//       -300
//       FormatException:
//          The value could not be parsed.
//       FormatException:
//          The value could not be parsed.
//       FormatException:
//          The value could not be parsed.
' Call parse with default values of style and provider
Console.WriteLine(BigInteger.Parse("  -300   ", _
                  NumberStyles.Integer, CultureInfo.CurrentCulture))
' Call parse with default values of style and provider supporting tilde as negative sign
Console.WriteLine(BigInteger.Parse("   ~300  ", _
                                   NumberStyles.Integer, New BigIntegerFormatProvider()))
' Call parse with only AllowLeadingWhite and AllowTrailingWhite
' Exception thrown because of presence of negative sign
Try
   Console.WriteLIne(BigInteger.Parse("    ~300   ", _
                                      NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite, _
                                      New BigIntegerFormatProvider()))
Catch e As FormatException
   Console.WriteLine("{0}: {1}   {2}", e.GetType().Name, vbCrLf, e.Message)
End Try                                   
' Call parse with only AllowHexSpecifier
' Exception thrown because of presence of negative sign
Try
   Console.WriteLIne(BigInteger.Parse("-3af", NumberStyles.AllowHexSpecifier, _
                                      New BigIntegerFormatProvider()))
Catch e As FormatException
   Console.WriteLine("{0}: {1}   {2}", e.GetType().Name, vbCrLf, e.Message)
End Try                                 
' Call parse with only NumberStyles.None
' Exception thrown because of presence of white space and sign
Try
   Console.WriteLIne(BigInteger.Parse(" -300 ", NumberStyles.None, _
                                      New BigIntegerFormatProvider()))
Catch e As FormatException
   Console.WriteLine("{0}: {1}   {2}", e.GetType().Name, vbCrLf, e.Message)
End Try
' The example displays the following output:
'       -300
'       -300
'       FormatException:
'          The value could not be parsed.
'       FormatException:
'          The value could not be parsed.
'       FormatException:
'          The value could not be parsed.

메서드에 대한 Parse(String, NumberStyles, IFormatProvider) 여러 개별 호출은 타일(~)을 음수 기호로 정의하는 다음 BigIntegerFormatProvider 클래스의 인스턴스를 전달합니다.

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

설명

매개 변수는 style 구문 분석 작업이 성공하기 위해 매개 변수에 허용되는 value 스타일 요소(예: 공백, 양수 또는 음수 기호, 그룹 구분 기호 또는 소수점 기호)를 정의합니다. styles 는 열거형의 비트 플래그 NumberStyles 조합이어야 합니다. 매개 변수는 style 16진수 값의 문자열 표현을 포함하는 경우 value , 가 나타내는 value 숫자 시스템(10진수 또는 16진수)이 런타임에만 알려지거나 에서 value공백 또는 기호 기호를 허용하지 않으려는 경우에 이 메서드 오버로드를 유용하게 만듭니다.

의 값 style에 따라 매개 변수에 value 다음 요소가 포함될 수 있습니다.

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

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

[ws] hexdigits[ws]

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

요소 설명
ws 선택적 공백입니다. 플래그가 포함된 경우 의 시작 value 부분에 공백이 NumberStyles.AllowLeadingWhite 표시될 수 있으며 플래그가 포함된 NumberStyles.AllowTrailingWhite 경우 stylevalue 끝에 표시될 수 style 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 위치는 매개 변수로 NumberFormatInfo.CurrencyNegativePattern 표시된 문화권의 및 NumberFormatInfo.CurrencyPositivePattern 속성에 의해 provider 정의됩니다. 플래그가 포함된 경우 style 현재 문화권의 통화 기호가 NumberStyles.AllowCurrencySymbolvalue 나타날 수 있습니다.
sign 선택적 기호입니다. 플래그가 포함된 경우 의 시작 value 부분에 기호가 NumberStyles.AllowLeadingSign 표시되고 플래그가 포함된 NumberStyles.AllowTrailingSign 경우 stylevalue 끝에 표시할 수 style 있습니다. 플래그가 포함된 NumberStyles.AllowParentheses 경우 style 괄호를 사용하여 value 음수 값을 나타낼 수 있습니다.
숫자

fractional_digits

exponential_digits
0에서 9까지의 숫자 시퀀스입니다. fractional_digits 경우 숫자 0만 유효합니다.
, 문화권별 그룹 구분 기호입니다. 에 지정된 provider 문화권의 그룹 구분 기호가 플래그를 포함하는 NumberStyles.AllowThousands 경우 stylevalue 나타날 수 있습니다.
. 문화권별 소수점 기호입니다. 에 지정된 provider 문화권의 소수점 기호는 플래그가 포함된 NumberStyles.AllowDecimalPoint 경우 stylevalue 나타날 수 있습니다. 구문 분석 작업이 성공하려면 숫자 0만 소수 자릿수로 표시할 수 있습니다. fractional_digits 다른 숫자가 포함되어 있으면 이 FormatException throw됩니다.
E 값이 지수(과학적) 표기법으로 표시됨을 나타내는 "e" 또는 "E" 문자입니다. 플래그가 포함된 경우 style 매개 변수는 value 지수 표기법으로 NumberStyles.AllowExponent 숫자를 나타낼 수 있습니다.
hexdigits 0에서 f까지 또는 0부터 F까지의 16진수 숫자 시퀀스입니다.

참고

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

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

NumberStyles 값 숫자 외에 값에 허용되는 요소
None digits 요소만 해당합니다.
AllowDecimalPoint 소수점(.) 및 소수 자릿수 요소입니다 .
AllowExponent 지수 표기법을 나타내는 "e" 또는 "E" 문자입니다. exponential_digits 함께.
AllowLeadingWhite 의 시작 부분에 있는 ws 요소입니다 value.
AllowTrailingWhite 의 끝에 있는 ws 요소입니다 value.
AllowLeadingSign 의 시작 부분에 있는 기호 요소입니다 value.
AllowTrailingSign 의 끝에 있는 기호 요소입니다 value.
AllowParentheses 숫자 값을 묶는 괄호 형식의 기호 요소입니다.
AllowThousands 그룹 구분 기호(,) 요소입니다.
AllowCurrencySymbol 통화($) 요소입니다.
Currency 모든 요소. 그러나 는 value 16진수 또는 지수 표기법으로 숫자를 나타낼 수 없습니다.
Float value 시작 또는 끝 부분에 있는 ws 요소,의 시작 부분에 있는 기호 및 소수점 (.) 기호를 지정 합니다. value 매개 변수는 value 지수 표기법을 사용할 수도 있습니다.
Number ws, sign, 그룹 구분 기호(,) 및 소수점(.) 요소입니다.
Any 모든 요소. 그러나 은 value 16진수를 나타낼 수 없습니다.

중요

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

에서 특정 스타일 요소를 valueNumberStyles.AllowHexSpecifier 허용하지만 필요하지 않은 다른 NumberStyles 값과 달리 스타일 값은 의 개별 숫자 문자가 항상 16진수 문자 value 로 해석됨을 의미합니다. 유효한 16진수 문자는 0-9, A-F 및 a-f입니다. 매개 변수와 style 결합할 수 있는 유일한 다른 플래그는 및 NumberStyles.AllowTrailingWhite입니다NumberStyles.AllowLeadingWhite. (열거형에는 NumberStyles 공백 플래그를 모두 포함하는 복합 숫자 스타일 HexNumber가 포함됩니다.)

참고

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

가 16진수 문자열인 경우 value 메서드는 처음 두 개의 16진수가 보다 크거나 같은 경우 두 개의 보수 표현을 사용하여 저장된 음수로 0x80해석 value 합니다.Parse(String, NumberStyles) 즉, 메서드는 의 첫 번째 바이트 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" };
      foreach (string hexString in hexStrings)
      {
         BigInteger number = BigInteger.Parse(hexString, NumberStyles.AllowHexSpecifier);
         Console.WriteLine("Converted 0x{0} to {1}.", hexString, number);
      }
   }
}
// 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" }
      For Each hexString As String In hexStrings
         Dim number As BigInteger = BigInteger.Parse(hexString, NumberStyles.AllowHexSpecifier)
         Console.WriteLine("Converted 0x{0} to {1}.", hexString, number)
      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 숫자 서식 정보를 제공하는 문화권을 나타내는 개체입니다. 해당 메서드는 GetFormatNumberFormatInfo 숫자 서식 정보를 제공하는 개체를 반환합니다.

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

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

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

추가 정보

적용 대상