SByte.ToString 메서드

정의

이 인스턴스의 숫자 값을 해당하는 문자열 표현으로 변환합니다.

오버로드

ToString()

이 인스턴스의 숫자 값을 해당하는 문자열 표현으로 변환합니다.

ToString(IFormatProvider)

지정된 문화권별 형식 정보를 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

ToString(String)

지정된 형식을 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

ToString(String, IFormatProvider)

지정된 형식 및 문화권별 형식 정보를 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

ToString()

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

이 인스턴스의 숫자 값을 해당하는 문자열 표현으로 변환합니다.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

반환

음수 부호(값이 음수일 경우)와 0부터 9 사이의 숫자(앞에 오는 0은 사용하지 않음)들로 구성된 이 인스턴스의 값에 대한 문자열 표현입니다.

예제

다음 예제에서는 기본 ToString() 메서드를 SByte 사용하여 값을 표시합니다. 또한 여러 표준 형식 지정자를 사용하여 발생하는 값의 SByte 문자열 표현도 표시합니다. 예제는 en-US 문화권의 서식 규칙을 사용하여 표시됩니다.

using System;

public class Example
{
   public static void Main()
   {
      sbyte value = -123;
      // Display value using default ToString method.
      Console.WriteLine(value.ToString());            // Displays -123
      // Display value using some standard format specifiers.
      Console.WriteLine(value.ToString("G"));         // Displays -123
      Console.WriteLine(value.ToString("C"));         // Displays ($-123.00)
      Console.WriteLine(value.ToString("D"));         // Displays -123
      Console.WriteLine(value.ToString("F"));         // Displays -123.00
      Console.WriteLine(value.ToString("N"));         // Displays -123.00
      Console.WriteLine(value.ToString("X"));         // Displays 85
   }
}
let value = -123y
// Display value using default ToString method.
printfn $"{value.ToString()}"               // Displays -123
// Display value using some standard format specifiers.
printfn $"""{value.ToString "G"}"""         // Displays -123
printfn $"""{value.ToString "C"}"""         // Displays ($-123.00)
printfn $"""{value.ToString "D"}"""         // Displays -123
printfn $"""{value.ToString "F"}"""         // Displays -123.00
printfn $"""{value.ToString "N"}"""         // Displays -123.00
printfn $"""{value.ToString "X"}"""         // Displays 85
Module Example
   Public Sub Main()
      Dim value As SByte = -123
      ' Display value using default ToString method.
      Console.WriteLine(value.ToString())            ' Displays -123
      ' Display value using some standard format specifiers.
      Console.WriteLine(value.ToString("G"))         ' Displays -123
      Console.WriteLine(value.ToString("C"))         ' Displays ($-123.00)
      Console.WriteLine(value.ToString("D"))         ' Displays -123
      Console.WriteLine(value.ToString("F"))         ' Displays -123.00
      Console.WriteLine(value.ToString("N"))         ' Displays -123.00
      Console.WriteLine(value.ToString("X"))         ' Displays 85
   End Sub
End Module

설명

메서드는 ToString() 현재 문화권의 기본("G" 또는 일반) 형식으로 값의 형식 SByte 을 지정합니다. 다른 형식이나 문화권을 지정하려면 다음과 같이 메서드의 ToString 다른 오버로드를 사용합니다.

형식을 사용하려면 문화권의 경우 오버로드 사용
기본("G") 형식 특정 문화권 ToString(IFormatProvider)
특정 형식 기본(현재) 문화권 ToString(String)
특정 형식 특정 문화권 ToString(String, IFormatProvider)

반환 값은 일반 숫자 형식 지정자("G")를 사용하여 형식이 지정됩니다. 값의 SByte 문자열 표현에는 값이 음수이면 음수 기호가 포함되고 앞에 오는 0이 없는 0에서 9까지의 숫자 시퀀스가 포함됩니다. 음수 기호는 현재 문화권에 NumberFormatInfo 대한 개체에 의해 정의됩니다.

서명된 바이트 값의 문자열 표현 서식을 정의하려면 메서드를 호출합니다 ToString(String) .

추가 정보

적용 대상

ToString(IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

지정된 문화권별 형식 정보를 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

public:
 virtual System::String ^ ToString(IFormatProvider ^ provider);
public:
 System::String ^ ToString(IFormatProvider ^ provider);
public string ToString (IFormatProvider provider);
public string ToString (IFormatProvider? provider);
override this.ToString : IFormatProvider -> string
Public Function ToString (provider As IFormatProvider) As String

매개 변수

provider
IFormatProvider

문화권별 형식 정보를 제공하는 개체입니다.

반환

provider에 의해 지정된 이 인스턴스 값의 문자열 표현입니다.

구현

예제

다음 예제에서는 사용자 지정 NumberFormatInfo 개체를 정의하고 해당 속성에 "~" 문자를 NegativeSign 할당합니다. 그런 다음 이 사용자 지정 개체와 NumberFormatInfo 고정 문화권의 개체를 사용하여 일련의 SByte 값에 서식을 지정합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Define a custom NumberFormatInfo object with "~" as its negative sign.
      NumberFormatInfo nfi = new NumberFormatInfo();
      nfi.NegativeSign = "~";
      
      // Initialize an array of SByte values.
      sbyte[] bytes = { -122, 17, 124 };

      // Display the formatted result using the custom provider.
      Console.WriteLine("Using the custom NumberFormatInfo object:");
      foreach (sbyte value in bytes)
         Console.WriteLine(value.ToString(nfi));

      Console.WriteLine();
          
      // Display the formatted result using the invariant culture.
      Console.WriteLine("Using the invariant culture:");
      foreach (sbyte value in bytes)
         Console.WriteLine(value.ToString(NumberFormatInfo.InvariantInfo));
   }
}
// The example displays the following output:
//       Using the custom NumberFormatInfo object:
//       ~122
//       17
//       124
//       
//       Using the invariant culture:
//       -122
//       17
//       124
open System.Globalization

// Define a custom NumberFormatInfo object with "~" as its negative sign.
let nfi = NumberFormatInfo(NegativeSign = "~")

// Initialize an array of SByte values.
let bytes = [| -122y; 17y; 124y |]

// Display the formatted result using the custom provider.
printfn "Using the custom NumberFormatInfo object:"
for value in bytes do
    printfn $"{value.ToString nfi}"

printfn ""
      
// Display the formatted result using the invariant culture.
printfn "Using the invariant culture:"
for value in bytes do
   printfn $"{value.ToString NumberFormatInfo.InvariantInfo}"
// The example displays the following output:
//       Using the custom NumberFormatInfo object:
//       ~122
//       17
//       124
//       
//       Using the invariant culture:
//       -122
//       17
//       124
Imports System.Globalization

Module Example
   Public Sub Main()
      ' Define a custom NumberFormatInfo object with "~" as its negative sign.
      Dim nfi As New NumberFormatInfo()
      nfi.NegativeSign = "~"
      
      ' Initialize an array of SByte values.
      Dim bytes() As SByte = { -122, 17, 124 }

      ' Display the formatted result using the custom provider.
      Console.WriteLine("Using the custom NumberFormatInfo object:")
      For Each value As SByte In bytes
         Console.WriteLine(value.ToString(nfi))
      Next
      Console.WriteLine()
          
      ' Display the formatted result using the invariant culture.
      Console.WriteLine("Using the invariant culture:")
      For Each value As SByte In bytes
         Console.WriteLine(value.ToString(NumberFormatInfo.InvariantInfo))
      Next   
   End Sub
End Module
' The example displays the following output:
'       Using the custom NumberFormatInfo object:
'       ~122
'       17
'       124
'       
'       Using the invariant culture:
'       -122
'       17
'       124

설명

메서드는 ToString(IFormatProvider)SByte 지정된 문화권의 기본("G" 또는 일반) 형식으로 값의 형식을 지정합니다. 다른 형식 또는 현재 문화권을 지정하려면 다음과 같이 메서드의 ToString 다른 오버로드를 사용합니다.

형식을 사용하려면 문화권의 경우 오버로드 사용
기본("G") 형식 기본(현재) 문화권 ToString()
특정 형식 기본(현재) 문화권 ToString(String)
특정 형식 특정 문화권 ToString(String, IFormatProvider)

provider 매개 변수는 구현입니다IFormatProvider. 해당 GetFormat 메서드는 이 메서드에서 NumberFormatInfo 반환하는 문자열 형식에 대한 문화권별 정보를 제공하는 개체를 반환합니다. 가 이nullprovider 값은 SByte 현재 문화권의 개체를 NumberFormatInfo 사용하여 형식이 지정됩니다. 일반 형식 지정자를 사용하여 값의 NumberFormatInfo 문자열 표현을 제어하는 개체의 SByte 유일한 속성은 음수 기호를 나타내는 문자를 정의하는 입니다 NumberFormatInfo.NegativeSign.

매개 변수는 provider 다음 중 하나일 수 있습니다.

추가 정보

적용 대상

ToString(String)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

지정된 형식을 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

public:
 System::String ^ ToString(System::String ^ format);
public string ToString (string format);
public string ToString (string? format);
override this.ToString : string -> string
Public Function ToString (format As String) As String

매개 변수

format
String

표준 또는 사용자 지정 숫자 서식 문자열입니다.

반환

이 인스턴스의 값을 format에 지정된 내용에 따라 나타낸 문자열 표현입니다.

예외

format이 잘못되었습니다.

예제

다음 예제에서는 값 배열 SByte 을 초기화하고 각 표준 형식 문자열과 일부 사용자 지정 서식 문자열을 사용하여 표시합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      sbyte[] values = { -124, 0, 118 };
      string[] specifiers = { "G", "C", "D3", "E2", "e3", "F", 
                              "N", "P", "X", "00.0", "#.0", 
                              "000;(0);**Zero**" };
      
      foreach (sbyte value in values)
      {
         foreach (string specifier in specifiers)
            Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//       G: -124
//       C: ($124.00)
//       D3: -124
//       E2: -1.24E+002
//       e3: -1.240e+002
//       F: -124.00
//       N: -124.00
//       P: -12,400.00 %
//       X: 84
//       00.0: -124.0
//       #.0: -124.0
//       000;(0);**Zero**: (124)
//       
//       G: 0
//       C: $0.00
//       D3: 000
//       E2: 0.00E+000
//       e3: 0.000e+000
//       F: 0.00
//       N: 0.00
//       P: 0.00 %
//       X: 0
//       00.0: 00.0
//       #.0: .0
//       000;(0);**Zero**: **Zero**
//       
//       G: 118
//       C: $118.00
//       D3: 118
//       E2: 1.18E+002
//       e3: 1.180e+002
//       F: 118.00
//       N: 118.00
//       P: 11,800.00 %
//       X: 76
//       00.0: 118.0
//       #.0: 118.0
//       000;(0);**Zero**: 118
let values = [| -124y; 0y; 118y |]
let specifiers = 
    [| "G"; "C"; "D3"; "E2"; "e3"; "F" 
       "N"; "P"; "X"; "00.0"; "#.0" 
       "000(0)**Zero**" |]

for value in values do
    for specifier in specifiers do
        printfn $"{specifier}: {value.ToString specifier}"
    printfn ""
// The example displays the following output:
//       G: -124
//       C: ($124.00)
//       D3: -124
//       E2: -1.24E+002
//       e3: -1.240e+002
//       F: -124.00
//       N: -124.00
//       P: -12,400.00 %
//       X: 84
//       00.0: -124.0
//       #.0: -124.0
//       000(0)**Zero**: (124)
//       
//       G: 0
//       C: $0.00
//       D3: 000
//       E2: 0.00E+000
//       e3: 0.000e+000
//       F: 0.00
//       N: 0.00
//       P: 0.00 %
//       X: 0
//       00.0: 00.0
//       #.0: .0
//       000(0)**Zero**: **Zero**
//       
//       G: 118
//       C: $118.00
//       D3: 118
//       E2: 1.18E+002
//       e3: 1.180e+002
//       F: 118.00
//       N: 118.00
//       P: 11,800.00 %
//       X: 76
//       00.0: 118.0
//       #.0: 118.0
//       000(0)**Zero**: 118
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim values() As SByte = { -124, 0, 118 }
      Dim specifiers() As String = { "G", "C", "D3", "E2", "e3", "F", _
                                     "N", "P", "X", "00.0", "#.0", _
                                     "000;(0);**Zero**" }
      
      For Each value As SByte In values
         For Each specifier As String In specifiers
            Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'       G: -124
'       C: ($124.00)
'       D3: -124
'       E2: -1.24E+002
'       e3: -1.240e+002
'       F: -124.00
'       N: -124.00
'       P: -12,400.00 %
'       X: 84
'       00.0: -124.0
'       #.0: -124.0
'       000;(0);**Zero**: (124)
'       
'       G: 0
'       C: $0.00
'       D3: 000
'       E2: 0.00E+000
'       e3: 0.000e+000
'       F: 0.00
'       N: 0.00
'       P: 0.00 %
'       X: 0
'       00.0: 00.0
'       #.0: .0
'       000;(0);**Zero**: **Zero**
'       
'       G: 118
'       C: $118.00
'       D3: 118
'       E2: 1.18E+002
'       e3: 1.180e+002
'       F: 118.00
'       N: 118.00
'       P: 11,800.00 %
'       X: 76
'       00.0: 118.0
'       #.0: 118.0
'       000;(0);**Zero**: 118

설명

메서드는 ToString(String) 현재 문화권 SByte 의 규칙을 사용하여 지정된 형식의 값 형식을 지정합니다. 기본 형식("G"또는 일반) 형식을 사용하거나 다른 문화권을 지정하려면 다음과 같이 메서드의 ToString 다른 오버로드를 사용합니다.

형식을 사용하려면 문화권의 경우 오버로드 사용
기본("G") 형식 기본(현재) 문화권 ToString()
기본("G") 형식 특정 문화권 ToString(IFormatProvider)
특정 형식 특정 문화권 ToString(String, IFormatProvider)

매개 변수는 format 유효한 표준 숫자 형식 지정자 또는 사용자 지정 숫자 형식 지정자의 조합일 수 있습니다. 가 String.Empty 또는 인 null경우 format 현재 SByte 개체의 반환 값은 일반 형식 지정자("G")로 서식이 지정됩니다. 가 다른 값이면 format 메서드는 을 FormatExceptionthrow합니다.

.NET은 다음과 같은 서식 지정 topics 자세히 설명하는 광범위한 서식 지정 지원을 제공합니다.

반환된 문자열의 형식은 현재 문화권에 NumberFormatInfo 대한 개체에 의해 결정됩니다. 매개 변수에 format 따라 이 개체는 출력 문자열의 음수 기호, 그룹 구분 기호 및 소수점 기호와 같은 기호를 제어합니다. 현재 문화권 이외의 문화권에 대한 서식 정보를 제공하려면 오버로드를 호출합니다 ToString(String, IFormatProvider) .

추가 정보

적용 대상

ToString(String, IFormatProvider)

Source:
SByte.cs
Source:
SByte.cs
Source:
SByte.cs

지정된 형식 및 문화권별 형식 정보를 사용하여 이 인스턴스의 숫자 값을 해당 문자열 표현으로 변환합니다.

public:
 virtual System::String ^ ToString(System::String ^ format, IFormatProvider ^ provider);
public string ToString (string format, IFormatProvider provider);
public string ToString (string? format, IFormatProvider? provider);
override this.ToString : string * IFormatProvider -> string
Public Function ToString (format As String, provider As IFormatProvider) As String

매개 변수

format
String

표준 또는 사용자 지정 숫자 서식 문자열입니다.

provider
IFormatProvider

문화권별 형식 정보를 제공하는 개체입니다.

반환

formatprovider로 지정된 이 인스턴스 값의 문자열 표현입니다.

구현

예외

format이 잘못되었습니다.

예제

다음 예제에서는 표준 숫자 형식 지정자와 여러 특정 CultureInfo 개체를 사용하여 양수 및 음 SByte 수 값을 모두 표시합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Define cultures whose formatting conventions are to be used.
      CultureInfo[] cultures = { CultureInfo.CreateSpecificCulture("en-US"), 
                                 CultureInfo.CreateSpecificCulture("fr-FR"), 
                                 CultureInfo.CreateSpecificCulture("es-ES") };
      sbyte positiveNumber = 119;
      sbyte negativeNumber = -45;
      string[] specifiers = {"G", "C", "D4", "E2", "F", "N", "P", "X2"}; 
      
      foreach (string specifier in specifiers)
      {
         foreach (CultureInfo culture in cultures)
            Console.WriteLine("{0,2} format using {1} culture: {2, 16} {3, 16}",  
                              specifier, culture.Name, 
                              positiveNumber.ToString(specifier, culture), 
                              negativeNumber.ToString(specifier, culture));
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//     G format using en-US culture:              119              -45
//     G format using fr-FR culture:              119              -45
//     G format using es-ES culture:              119              -45
//    
//     C format using en-US culture:          $119.00         ($45.00)
//     C format using fr-FR culture:         119,00 €         -45,00 €
//     C format using es-ES culture:         119,00 €         -45,00 €
//    
//    D4 format using en-US culture:             0119            -0045
//    D4 format using fr-FR culture:             0119            -0045
//    D4 format using es-ES culture:             0119            -0045
//    
//    E2 format using en-US culture:        1.19E+002       -4.50E+001
//    E2 format using fr-FR culture:        1,19E+002       -4,50E+001
//    E2 format using es-ES culture:        1,19E+002       -4,50E+001
//    
//     F format using en-US culture:           119.00           -45.00
//     F format using fr-FR culture:           119,00           -45,00
//     F format using es-ES culture:           119,00           -45,00
//    
//     N format using en-US culture:           119.00           -45.00
//     N format using fr-FR culture:           119,00           -45,00
//     N format using es-ES culture:           119,00           -45,00
//    
//     P format using en-US culture:      11,900.00 %      -4,500.00 %
//     P format using fr-FR culture:      11 900,00 %      -4 500,00 %
//     P format using es-ES culture:      11.900,00 %      -4.500,00 %
//    
//    X2 format using en-US culture:               77               D3
//    X2 format using fr-FR culture:               77               D3
//    X2 format using es-ES culture:               77               D3
open System.Globalization

// Define cultures whose formatting conventions are to be used.
let cultures = 
    [| CultureInfo.CreateSpecificCulture "en-US" 
       CultureInfo.CreateSpecificCulture "fr-FR" 
       CultureInfo.CreateSpecificCulture "es-ES" |]
let positiveNumber = 119y
let negativeNumber = -45y
let specifiers = [| "G"; "C"; "D4"; "E2"; "F"; "N"; "P"; "X2" |]

for specifier in specifiers do
    for culture in cultures do
        printfn $"{specifier,2} format using {culture.Name} culture: {positiveNumber.ToString(specifier, culture), 16} {negativeNumber.ToString(specifier, culture), 16}"
    printfn ""
// The example displays the following output:
//     G format using en-US culture:              119              -45
//     G format using fr-FR culture:              119              -45
//     G format using es-ES culture:              119              -45
//    
//     C format using en-US culture:          $119.00         ($45.00)
//     C format using fr-FR culture:         119,00 €         -45,00 €
//     C format using es-ES culture:         119,00 €         -45,00 €
//    
//    D4 format using en-US culture:             0119            -0045
//    D4 format using fr-FR culture:             0119            -0045
//    D4 format using es-ES culture:             0119            -0045
//    
//    E2 format using en-US culture:        1.19E+002       -4.50E+001
//    E2 format using fr-FR culture:        1,19E+002       -4,50E+001
//    E2 format using es-ES culture:        1,19E+002       -4,50E+001
//    
//     F format using en-US culture:           119.00           -45.00
//     F format using fr-FR culture:           119,00           -45,00
//     F format using es-ES culture:           119,00           -45,00
//    
//     N format using en-US culture:           119.00           -45.00
//     N format using fr-FR culture:           119,00           -45,00
//     N format using es-ES culture:           119,00           -45,00
//    
//     P format using en-US culture:      11,900.00 %      -4,500.00 %
//     P format using fr-FR culture:      11 900,00 %      -4 500,00 %
//     P format using es-ES culture:      11.900,00 %      -4.500,00 %
//    
//    X2 format using en-US culture:               77               D3
//    X2 format using fr-FR culture:               77               D3
//    X2 format using es-ES culture:               77               D3
Imports System.Globalization

Module Example
   Public Sub Main()
      ' Define cultures whose formatting conventions are to be used.
      Dim cultures() As CultureInfo = {CultureInfo.CreateSpecificCulture("en-US"), _
                                       CultureInfo.CreateSpecificCulture("fr-FR"), _
                                       CultureInfo.CreateSpecificCulture("es-ES") }
      Dim positiveNumber As SByte = 119
      Dim negativeNumber As SByte = -45
      Dim specifiers() As String = {"G", "C", "D4", "E2", "F", "N", "P", "X2"} 
      
      For Each specifier As String In specifiers
         For Each culture As CultureInfo In Cultures
            Console.WriteLine("{0,2} format using {1} culture: {2, 16} {3, 16}", _ 
                              specifier, culture.Name, _
                              positiveNumber.ToString(specifier, culture), _
                              negativeNumber.ToString(specifier, culture))

         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'     G format using en-US culture:              119              -45
'     G format using fr-FR culture:              119              -45
'     G format using es-ES culture:              119              -45
'    
'     C format using en-US culture:          $119.00         ($45.00)
'     C format using fr-FR culture:         119,00 €         -45,00 €
'     C format using es-ES culture:         119,00 €         -45,00 €
'    
'    D4 format using en-US culture:             0119            -0045
'    D4 format using fr-FR culture:             0119            -0045
'    D4 format using es-ES culture:             0119            -0045
'    
'    E2 format using en-US culture:        1.19E+002       -4.50E+001
'    E2 format using fr-FR culture:        1,19E+002       -4,50E+001
'    E2 format using es-ES culture:        1,19E+002       -4,50E+001
'    
'     F format using en-US culture:           119.00           -45.00
'     F format using fr-FR culture:           119,00           -45,00
'     F format using es-ES culture:           119,00           -45,00
'    
'     N format using en-US culture:           119.00           -45.00
'     N format using fr-FR culture:           119,00           -45,00
'     N format using es-ES culture:           119,00           -45,00
'    
'     P format using en-US culture:      11,900.00 %      -4,500.00 %
'     P format using fr-FR culture:      11 900,00 %      -4 500,00 %
'     P format using es-ES culture:      11.900,00 %      -4.500,00 %
'    
'    X2 format using en-US culture:               77               D3
'    X2 format using fr-FR culture:               77               D3
'    X2 format using es-ES culture:               77               D3

설명

메서드는 ToString(String, IFormatProvider) 지정된 문화권 SByte 의 지정된 형식으로 값의 형식을 지정합니다. 기본 형식 또는 문화권 설정을 사용하려면 다음과 같이 메서드의 ToString 다른 오버로드를 사용합니다.

형식을 사용하려면 문화권의 경우 오버로드 사용
기본("G") 형식 기본(현재) 문화권 ToString()
기본("G") 형식 특정 문화권 ToString(IFormatProvider)
특정 형식 기본(현재) 문화권 ToString(String)

매개 변수는 format 유효한 표준 숫자 형식 지정자 또는 사용자 지정 숫자 형식 지정자의 조합일 수 있습니다. 가 String.Empty 또는 인 null경우 format 현재 SByte 개체의 반환 값은 일반 형식 지정자("G")로 서식이 지정됩니다. 가 다른 값이면 format 메서드는 을 FormatExceptionthrow합니다.

.NET은 다음과 같은 서식 지정 topics 자세히 설명하는 광범위한 서식 지정 지원을 제공합니다.

매개 변수는 provider 구현입니다 IFormatProvider . 해당 메서드는 GetFormat 이 메서드에서 NumberFormatInfo 반환된 문자열의 형식에 대한 문화권별 정보를 제공하는 개체를 반환합니다. 메서드가 ToString(String, IFormatProvider) 호출되면 매개 변수의 IFormatProvider.GetFormat 메서드를 provider 호출하고 형식을 나타내는 개체로 Type 전달합니다NumberFormatInfo. 그런 다음 메서드는 GetFormat 음수 NumberFormatInfo 기호, 그룹 구분 기호 또는 소수점 기호와 같은 매개 변수의 서식을 지정 value 하기 위한 정보를 제공하는 개체를 반환합니다. 매개 변수를 사용하여 메서드에 provider 서식 정보를 ToString(String, IFormatProvider) 제공하는 세 가지 방법이 있습니다.

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

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

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

가 이nullprovider 반환된 문자열의 서식은 현재 문화권 NumberFormatInfo 의 개체를 기반으로 합니다.

추가 정보

적용 대상