Int64.TryParse 메서드

정의

숫자의 문자열 표현을 해당하는 64비트 부호 있는 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

오버로드

TryParse(String, Int64)

숫자의 문자열 표현을 해당하는 64비트 부호 있는 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(ReadOnlySpan<Char>, Int64)

숫자의 범위 표현을 해당하는 부호 있는 64비트 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(String, NumberStyles, IFormatProvider, Int64)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 64비트 부호 있는 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

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

지정된 스타일 및 문화권별 형식으로 된 숫자의 범위 표현을 해당하는 64비트 부호 있는 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

TryParse(String, Int64)

숫자의 문자열 표현을 해당하는 64비트 부호 있는 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

public:
 static bool TryParse(System::String ^ s, [Runtime::InteropServices::Out] long % result);
public static bool TryParse (string s, out long result);
public static bool TryParse (string? s, out long result);
static member TryParse : string * int64 -> bool
Public Shared Function TryParse (s As String, ByRef result As Long) As Boolean

매개 변수

s
String

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

result
Int64

이 메서드는 변환이 성공한 경우 s에 포함된 숫자의 64비트 부호 있는 정수 값을 반환하고, 변환이 실패한 경우 0을 반환합니다. s 매개 변수가 null 또는 Empty이거나, 형식이 올바르지 않거나, MinValue보다 작거나 MaxValue보다 큰 숫자를 나타내는 경우 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어쓰게 됩니다.

반환

Boolean

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

예제

다음 예제에서는 Int64.TryParse(String, Int64) 다양한 문자열 값을 사용하여 메서드를 호출합니다.

using System;

public class StringParsing
{
   public static void Main()
   {
      TryToParse(null);
      TryToParse("160519");
      TryToParse("9432.0");
      TryToParse("16,667");
      TryToParse("   -322   ");
      TryToParse("+4302");
      TryToParse("(100);");
      TryToParse("01FA");
   }

   private static void TryToParse(string value)
   {
      bool success = Int64.TryParse(value, out long number);
      if (success)
      {
         Console.WriteLine("Converted '{0}' to {1}.", value, number);
      }
      else
      {
         if (value == null) value = "";
         Console.WriteLine("Attempted conversion of '{0}' failed.", value);
      }
   }
}
// The example displays the following output to the console:
//       Attempted conversion of '' failed.
//       Converted '160519' to 160519.
//       Attempted conversion of '9432.0' failed.
//       Attempted conversion of '16,667' failed.
//       Converted '   -322   ' to -322.
//       Converted '+4302' to 4302.
//       Attempted conversion of '(100);' failed.
//       Attempted conversion of '01FA' failed.
open System

let tryToParse (value: string) =
    match Int64.TryParse value with
    | true, number ->
        printfn $"Converted '{value}' to {number}."
    | _ ->
        let value =
            if isNull value then 
                ""
            else
                value
        printfn $"Attempted conversion of '{value}' failed."

tryToParse null
tryToParse "160519"
tryToParse "9432.0"
tryToParse "16,667"
tryToParse "   -322   "
tryToParse "+4302"
tryToParse "(100);"
tryToParse "01FA"


// The example displays the following output to the console:
//       Attempted conversion of '' failed.
//       Converted '160519' to 160519.
//       Attempted conversion of '9432.0' failed.
//       Attempted conversion of '16,667' failed.
//       Converted '   -322   ' to -322.
//       Converted '+4302' to 4302.
//       Attempted conversion of '(100);' failed.
//       Attempted conversion of '01FA' failed.
Module StringParsing
   Public Sub Main()
      TryToParse(Nothing)
      TryToParse("160519")
      TryToParse("9432.0")
      TryToParse("16,667")
      TryToParse("   -322   ")
      TryToParse("+4302")
      TryToParse("(100)")
      TryToParse("01FA")
   End Sub
   
   Private Sub TryToParse(value As String)
      Dim number As Long
      Dim result As Boolean = Int64.TryParse(value, number)
      If result Then
         Console.WriteLine("Converted '{0}' to {1}.", value, number)
      Else
         If value Is Nothing Then value = "" 
         Console.WriteLine("Attempted conversion of '{0}' failed.", value)
      End If     
   End Sub
End Module
' The example displays the following output to the console:
'       Attempted conversion of '' failed.
'       Converted '160519' to 160519.
'       Attempted conversion of '9432.0' failed.
'       Attempted conversion of '16,667' failed.
'       Converted '   -322   ' to -322.
'       Converted '+4302' to 4302.
'       Attempted conversion of '(100)' failed.
'       Attempted conversion of '01FA' failed.

이 예제에서 메서드가 변환할 수 없는 문자열 중 일부는 TryParse(String, Int64) 다음과 같습니다.

  • "9432.0". 문자열에 소수 구분 기호를 포함할 수 없으므로 변환이 실패합니다. 숫자만 포함해야 합니다.

  • "16,667". 문자열에 그룹 구분 기호를 포함할 수 없으므로 변환이 실패합니다. 숫자만 포함해야 합니다.

  • "(100)". 문자열에 현재 문화권의 및 속성으로 정의된 기호 이외의 음수 기호를 포함할 수 없으므로 변환이 NumberFormatInfo.NegativeSign NumberFormatInfo.NumberNegativePattern 실패합니다.

  • "01FA". 문자열에 16진수 숫자를 포함할 수 없으므로 변환이 실패합니다. 10진수만 포함해야 합니다.

설명

TryParse메서드는 메서드와 유사합니다. Parse 단, TryParse 변환이 실패할 경우 메서드가 예외를 throw하지 않습니다. 유효하지 FormatException 않고 성공적으로 구문 분석할 수 없는 경우 예외 처리를 사용하여 를 테스트할 필요가 s 없습니다.

s매개 변수에는 다음과 같은 여러 형식이 포함됩니다.

[ws] [sign]digits[ws]

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

요소 설명
ws 선택적 공백입니다.
sign 선택적 기호입니다.
숫자 0에서 9까지의 숫자 시퀀스입니다.

s매개 변수는 스타일을 사용하여 해석됩니다. NumberStyles.Integer 10진수 외에도 선행 및 후행 공백과 선행 기호가 함께 허용됩니다. 에 있을 수 있는 문화권별 서식 지정 정보와 함께 스타일 요소를 명시적으로 정의 하려면 s 사용 된 TryParse(String, NumberStyles, IFormatProvider, Int64) 메서드.

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

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

추가 정보

적용 대상

TryParse(ReadOnlySpan<Char>, Int64)

숫자의 범위 표현을 해당하는 부호 있는 64비트 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

public:
 static bool TryParse(ReadOnlySpan<char> s, [Runtime::InteropServices::Out] long % result);
public static bool TryParse (ReadOnlySpan<char> s, out long result);
static member TryParse : ReadOnlySpan<char> * int64 -> bool
Public Shared Function TryParse (s As ReadOnlySpan(Of Char), ByRef result As Long) As Boolean

매개 변수

s
ReadOnlySpan<Char>

변환할 숫자를 나타내는 문자를 포함하는 범위입니다.

result
Int64

이 메서드는 변환이 성공한 경우 s에 포함된 숫자의 64비트 부호 있는 정수 값을 반환하고, 변환이 실패한 경우 0을 반환합니다. s 매개 변수가 null 또는 Empty이거나, 형식이 올바르지 않거나, MinValue보다 작거나 MaxValue보다 큰 숫자를 나타내는 경우 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어쓰게 됩니다.

반환

Boolean

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

적용 대상

TryParse(String, NumberStyles, IFormatProvider, Int64)

지정된 스타일 및 문화권별 형식으로 된 숫자의 문자열 표현을 해당하는 64비트 부호 있는 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

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

매개 변수

s
String

변환할 숫자가 포함된 문자열입니다. 이 문자열은 style이 지정하는 스타일을 사용하여 해석됩니다.

style
NumberStyles

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

provider
IFormatProvider

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

result
Int64

이 메서드는 변환이 성공한 경우 s에 포함된 숫자의 64비트 부호 있는 정수 값을 반환하고, 변환이 실패한 경우 0을 반환합니다. s 매개 변수가 null 또는 Empty이거나, 형식이 style과 호환되지 않거나, MinValue보다 작거나 MaxValue보다 큰 숫자를 나타내는 경우 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어쓰게 됩니다.

반환

Boolean

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

예외

styleNumberStyles 값이 아닙니다.

또는 styleAllowHexSpecifierHexNumber 값의 조합이 아닙니다.

예제

다음 예제에서는 TryParse(String, NumberStyles, IFormatProvider, Int64) 다양한 문자열과 값을 사용하여 메서드를 NumberStyles 호출합니다.

using System;
using System.Globalization;

public class StringParsing
{
   public static void Main()
   {
      string numericString;
      NumberStyles styles;

      numericString = "106779";
      styles = NumberStyles.Integer;
      CallTryParse(numericString, styles);

      numericString = "-30677";
      styles = NumberStyles.None;
      CallTryParse(numericString, styles);

      styles = NumberStyles.AllowLeadingSign;
      CallTryParse(numericString, styles);

      numericString = "301677-";
      CallTryParse(numericString, styles);

      styles = styles | NumberStyles.AllowTrailingSign;
      CallTryParse(numericString, styles);

      numericString = "$10634";
      styles = NumberStyles.Integer;
      CallTryParse(numericString, styles);

      styles = NumberStyles.Integer | NumberStyles.AllowCurrencySymbol;
      CallTryParse(numericString, styles);

      numericString = "10345.00";
      styles = NumberStyles.Integer | NumberStyles.AllowDecimalPoint;
      CallTryParse(numericString, styles);

      numericString = "10345.72";
      styles = NumberStyles.Integer | NumberStyles.AllowDecimalPoint;
      CallTryParse(numericString, styles);

      numericString = "22,593";
      styles = NumberStyles.Integer | NumberStyles.AllowThousands;
      CallTryParse(numericString, styles);

      numericString = "12E-01";
      styles = NumberStyles.Integer | NumberStyles.AllowExponent;
      CallTryParse(numericString, styles);

      numericString = "12E03";
      CallTryParse(numericString, styles);

      numericString = "80c1";
      CallTryParse(numericString, NumberStyles.HexNumber);

      numericString = "0x80C1";
      CallTryParse(numericString, NumberStyles.HexNumber);
   }

   private static void CallTryParse(string stringToConvert, NumberStyles styles)
   {
      CultureInfo provider;

      // If currency symbol is allowed, use en-US culture.
      if ((styles & NumberStyles.AllowCurrencySymbol) > 0)
         provider = new CultureInfo("en-US");
      else
         provider = CultureInfo.InvariantCulture;

      bool success = Int64.TryParse(stringToConvert, styles,
                                   provider, out long number);
      if (success)
         Console.WriteLine($"Converted '{stringToConvert}' to {number}.");
      else
         Console.WriteLine($"Attempted conversion of '{stringToConvert}' failed.");
   }
}
// The example displays the following output to the console:
//       Converted '106779' to 106779.
//       Attempted conversion of '-30677' failed.
//       Converted '-30677' to -30677.
//       Attempted conversion of '301677-' failed.
//       Converted '301677-' to -301677.
//       Attempted conversion of '$10634' failed.
//       Converted '$10634' to 10634.
//       Converted '10345.00' to 10345.
//       Attempted conversion of '10345.72' failed.
//       Converted '22,593' to 22593.
//       Attempted conversion of '12E-01' failed.
//       Converted '12E03' to 12000.
//       Converted '80c1' to 32961.
//       Attempted conversion of '0x80C1' failed.
open System
open System.Globalization

let callTryParse (stringToConvert: string) styles =
    let provider =
        // If currency symbol is allowed, use en-US culture.
        if int (styles &&& NumberStyles.AllowCurrencySymbol) > 0 then
            CultureInfo "en-US"
        else
            CultureInfo.InvariantCulture

    match Int64.TryParse(stringToConvert, styles, provider) with
    | true, number ->
        printfn $"Converted '{stringToConvert}' to {number}."
    | _ ->
        printfn $"Attempted conversion of '{stringToConvert}' failed."


[<EntryPoint>]
let main _ =
    let numericString = "106779"
    let styles = NumberStyles.Integer
    callTryParse numericString styles

    let numericString = "-30677"
    let styles = NumberStyles.None
    callTryParse numericString styles

    let styles = NumberStyles.AllowLeadingSign
    callTryParse numericString styles

    let numericString = "301677-"
    callTryParse numericString styles

    let styles = styles ||| NumberStyles.AllowTrailingSign
    callTryParse numericString styles

    let numericString = "$10634"
    let styles = NumberStyles.Integer
    callTryParse numericString styles

    let styles = NumberStyles.Integer ||| NumberStyles.AllowCurrencySymbol
    callTryParse numericString styles

    let numericString = "10345.00"
    let styles = NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint
    callTryParse numericString styles

    let numericString = "10345.72"
    let styles = NumberStyles.Integer ||| NumberStyles.AllowDecimalPoint
    callTryParse numericString styles

    let numericString = "22,593"
    let styles = NumberStyles.Integer ||| NumberStyles.AllowThousands
    callTryParse numericString styles

    let numericString = "12E-01"
    let styles = NumberStyles.Integer ||| NumberStyles.AllowExponent
    callTryParse numericString styles

    let numericString = "12E03"
    callTryParse numericString styles

    let numericString = "80c1"
    callTryParse numericString NumberStyles.HexNumber

    let numericString = "0x80C1"
    callTryParse numericString NumberStyles.HexNumber

    0

// The example displays the following output to the console:
//       Converted '106779' to 106779.
//       Attempted conversion of '-30677' failed.
//       Converted '-30677' to -30677.
//       Attempted conversion of '301677-' failed.
//       Converted '301677-' to -301677.
//       Attempted conversion of '$10634' failed.
//       Converted '$10634' to 10634.
//       Converted '10345.00' to 10345.
//       Attempted conversion of '10345.72' failed.
//       Converted '22,593' to 22593.
//       Attempted conversion of '12E-01' failed.
//       Converted '12E03' to 12000.
//       Converted '80c1' to 32961.
//       Attempted conversion of '0x80C1' failed.
Imports System.Globalization

Module StringParsing
   Public Sub Main()
      Dim numericString As String
      Dim styles As NumberStyles
      
      numericString = "106779"
      styles = NumberStyles.Integer
      CallTryParse(numericString, styles)
      
      numericString = "-30677"
      styles = NumberStyles.None
      CallTryParse(numericString, styles)
      
      styles = NumberStyles.AllowLeadingSign
      CallTryParse(numericString, styles)
      
      numericString = "301677-"
      CallTryParse(numericString, styles)
      
      styles = styles Or NumberStyles.AllowTrailingSign
      CallTryParse(numericString, styles)
      
      numericString = "$10634"
      styles = NumberStyles.Integer
      CallTryParse(numericString, styles)
      
      styles = NumberStyles.Integer Or NumberStyles.AllowCurrencySymbol
      CallTryParse(numericString, styles)

      numericString = "10345.00"
      styles = NumberStyles.Integer Or NumberStyles.AllowDecimalPoint
      CallTryParse(numericString, styles)
      
      numericString = "10345.72"
      styles = NumberStyles.Integer Or NumberStyles.AllowDecimalPoint
      CallTryParse(numericString, styles)

      numericString = "22,593" 
      styles = NumberStyles.Integer Or NumberStyles.AllowThousands
      CallTryParse(numericString, styles)
      
      numericString = "12E-01"
      styles = NumberStyles.Integer Or NumberStyles.AllowExponent
      CallTryParse(numericString, styles) 
          
      numericString = "12E03"
      CallTryParse(numericString, styles) 
      
      numericString = "80c1"
      CallTryParse(numericString, NumberStyles.HexNumber)
      
      numericString = "0x80C1"
      CallTryParse(numericString, NumberStyles.HexNumber)
   End Sub
   
   Private Sub CallTryParse(stringToConvert As String, styles AS NumberStyles)
      Dim number As Long
      Dim provider As CultureInfo
      
      ' If currency symbol is allowed, use en-US culture.
      If CBool(styles And NumberStyles.AllowCurrencySymbol) Then
         provider = CultureInfo.CurrentCulture
      Else
         provider = New CultureInfo("en-US")
      End If
      
      Dim result As Boolean = Int64.TryParse(stringToConvert, styles, _
                                             provider, number)
      If result Then
         Console.WriteLine("Converted '{0}' to {1}.", stringToConvert, number)
      Else
         Console.WriteLine("Attempted conversion of '{0}' failed.", _
                           Convert.ToString(stringToConvert))
      End If                                                                           
   End Sub
End Module
' The example displays the following output to the console:
'       Converted '106779' to 106779.
'       Attempted conversion of '-30677' failed.
'       Converted '-30677' to -30677.
'       Attempted conversion of '301677-' failed.
'       Converted '301677-' to -301677.
'       Attempted conversion of '$10634' failed.
'       Converted '$10634' to 10634.
'       Converted '10345.00' to 10345.
'       Attempted conversion of '10345.72' failed.
'       Converted '22,593' to 22593.
'       Attempted conversion of '12E-01' failed.
'       Converted '12E03' to 12000.
'       Converted '80c1' to 32961.
'       Attempted conversion of '0x80C1' failed.

설명

TryParse메서드는 메서드와 유사합니다. Parse 단, TryParse 변환이 실패할 경우 메서드가 예외를 throw하지 않습니다. 유효하지 FormatException 않고 성공적으로 구문 분석할 수 없는 경우 예외 처리를 사용하여 를 테스트할 필요가 s 없습니다.

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

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

또는 매개 변수에 가 포함된 경우 style NumberStyles.AllowHexSpecifier 입니다.

[ws]hexdigits[ws]

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

요소 설명
ws 선택적 공백입니다. 에 플래그가 포함되어 있으면 의 시작 부분에 s style 공백이 NumberStyles.AllowLeadingWhite 표시되거나, 가 플래그를 포함하는 경우 의 끝에 s style 공백이 나타날 수 NumberStyles.AllowTrailingWhite 있습니다.
$ 문화권별 통화 기호입니다. 문자열의 해당 위치는 매개 CurrencyPositivePattern NumberFormatInfo 변수의 메서드에서 반환된 개체의 속성에 의해 GetFormat 정의됩니다. provider 에 플래그가 포함된 경우 통화 기호가 에 나타날 수 s style NumberStyles.AllowCurrencySymbol 있습니다.
sign 선택적 기호입니다. 또는 플래그가 포함된 경우 기호 기호가 에 나타날 수 s style NumberStyles.AllowLeadingSign NumberStyles.AllowTrailingSign 있습니다.
숫자

fractional_digits

exponential_digits
0에서 9까지의 숫자 시퀀스입니다. fractional_digits 의 경우 숫자 0만 유효합니다.
, 문화권별 천분 구분 기호입니다. 에 지정된 문화권의 천 구분 기호는 provider 에 플래그가 포함된 경우 에 나타날 수 s style NumberStyles.AllowThousands 있습니다.
. 문화권별 소수점 기호입니다. 에 지정된 문화권의 소수점 기호는 provider 에 플래그가 포함된 경우 에 나타날 수 s style NumberStyles.AllowDecimalPoint 있습니다.
e 값이 지수 표기법으로 표시되었음을 나타내는 'e' 또는 'E' 문자입니다. s에 플래그가 포함된 경우 매개 변수는 지수 표기법으로 숫자를 나타낼 수 style NumberStyles.AllowExponent 있습니다.
hexdigits 0부터 f까지 또는 0부터 F까지의 16진수 시퀀스입니다.

참고

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

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

비 복합 NumberStyles 값 숫자 외에 s에 허용되는 요소
NumberStyles.None 10진수만 해당합니다.
NumberStyles.AllowDecimalPoint 소수점()입니다. ) 및 fractional_digits 요소입니다. 그러나 fractional_digits 하나 이상의 숫자로만 구성되어야 합니다. 그렇지 않거나 메서드가 를 false 반환합니다.
NumberStyles.AllowExponent s매개 변수는 지수 표기법도 사용할 수 있습니다. s매개 변수는 0이 아닌 소수 구성 요소가 없는 데이터 형식 범위 내의 정수를 나타내야 Int64 합니다.
NumberStyles.AllowLeadingWhite 의 시작 부분에 있는 ws s 요소입니다.
NumberStyles.AllowTrailingWhite 끝에 있는 ws s 요소입니다.
NumberStyles.AllowLeadingSign 숫자 앞에 부호가 나타날 수 있습니다.
NumberStyles.AllowTrailingSign 숫자 뒤의 부호가 나타날 수 있습니다.
NumberStyles.AllowParentheses 숫자 값을 묶는 괄호 형식의 부호 요소입니다.
NumberStyles.AllowThousands 천 구분 기호( , ) 요소입니다.
NumberStyles.AllowCurrencySymbol $ 요소입니다.
NumberStyles.Currency 모든 요소입니다. s매개 변수는 16진수 또는 지수 표기법으로 숫자를 나타낼 수 없습니다.
NumberStyles.Float 의 시작 또는 끝에 있는 ws s 요소, 의 시작 부분에 부호, s 소수점( . ) 기호입니다. s매개 변수는 지수 표기법도 사용할 수 있습니다.
NumberStyles.Number ws, sign, thousands separator (,), decimal point (.) 요소입니다.
NumberStyles.Any 를 제외한 모든 스타일은 s 16진수를 나타낼 수 없습니다.

플래그를 사용하는 경우 NumberStyles.AllowHexSpecifiers 접두사 없이 16진수 값이어야 합니다. 예를 들어 "C9AF3"은 성공적으로 구문 분석되지만 "0xC9AF3"은 구문 분석하지 않습니다. 에 있을 수 있는 다른 style 플래그는 NumberStyles.AllowLeadingWhiteNumberStyles.AllowTrailingWhite 뿐입니다. NumberStyles열거형에는 공백 플래그를 모두 포함하는 복합 스타일 가 있습니다. NumberStyles.HexNumber

provider매개 변수는 IFormatProvider CultureInfo 메서드가 개체를 반환하는 개체 또는 개체와 같은 NumberFormatInfo GetFormat NumberFormatInfo 구현입니다. NumberFormatInfo개체는 형식에 대한 문화권별 정보를 s 제공합니다. providernull 이면 NumberFormatInfo 현재 문화권에 대한 개체가 사용됩니다.

추가 정보

적용 대상

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

지정된 스타일 및 문화권별 형식으로 된 숫자의 범위 표현을 해당하는 64비트 부호 있는 정수로 변환합니다. 반환 값은 변환이 성공했는지 아니면 실패했는지를 나타냅니다.

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

매개 변수

s
ReadOnlySpan<Char>

변환할 숫자를 나타내는 문자를 포함하는 범위입니다. style에서 지정된 스타일을 사용하여 해석하는 범위입니다.

style
NumberStyles

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

provider
IFormatProvider

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

result
Int64

이 메서드는 변환이 성공한 경우 s에 포함된 숫자의 64비트 부호 있는 정수 값을 반환하고, 변환이 실패한 경우 0을 반환합니다. s 매개 변수가 null 또는 Empty이거나, 형식이 style과 호환되지 않거나, MinValue보다 작거나 MaxValue보다 큰 숫자를 나타내는 경우 변환이 실패합니다. 이 매개 변수는 초기화되지 않은 상태로 전달됩니다. 원래 result에 제공된 모든 값을 덮어쓰게 됩니다.

반환

Boolean

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

적용 대상