UInt16.ToString 메서드

정의

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

오버로드

ToString(IFormatProvider)

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

ToString(String)

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

ToString(String, IFormatProvider)

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

ToString()

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

ToString(IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.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

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

반환

부호나 앞에 오는 0 없이 0에서 9 사이의 숫자 시퀀스로 구성된 이 인스턴스 값의 문자열 표현입니다.

구현

예제

다음 예제에서는 고정 문화권에 대한 형식 공급자를 포함하여 여러 형식 공급자를 사용하여 16비트 부속 정수 값의 서식을 지정합니다. 예제의 출력은 형식 공급자에 관계없이 메서드에서 반환 ToString(IFormatProvider) 된 형식이 지정된 문자열이 동일하다는 것을 보여 줍니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      // Define an array of CultureInfo objects.
      CultureInfo[] ci = { new CultureInfo("en-US"), 
                           new CultureInfo("fr-FR"), 
                           CultureInfo.InvariantCulture }; 
      UInt16 value = 18924;
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", 
                        GetName(ci[0]), GetName(ci[1]), GetName(ci[2])); 
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", 
                        value.ToString(ci[0]), value.ToString(ci[1]), value.ToString(ci[2]));   
   }

   private static string GetName(CultureInfo ci)
   {
      if (ci.Equals(CultureInfo.InvariantCulture))
         return "Invariant";
      else
         return ci.Name;         
   }
}
// The example displays the following output:
//          en-US          fr-FR      Invariant
//          18924          18924          18924
open System.Globalization

let getName (ci: CultureInfo) =
    if ci.Equals CultureInfo.InvariantCulture then "Invariant"
    else ci.Name

// Define an array of CultureInfo objects.
let ci = 
    [| CultureInfo "en-US" 
       CultureInfo "fr-FR" 
       CultureInfo.InvariantCulture |] 

let value = 18924us
printfn $"  {getName ci[0],12}   {getName ci[1],12}   {getName ci[2],12}"
printfn $"  {value.ToString ci[0],12}   {value.ToString ci[1],12}   {value.ToString ci[2],12}"
// The example displays the following output:
//          en-US          fr-FR      Invariant
//          18924          18924          18924
Imports System.Globalization

Module Example
   Public Sub Main()
      ' Define an array of CultureInfo objects.
      Dim ci() As CultureInfo = { New CultureInfo("en-US"), _
                                  New CultureInfo("fr-FR"), _
                                  CultureInfo.InvariantCulture } 
      Dim value As UInt16 = 18924
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", _
                        GetName(ci(0)), GetName(ci(1)), GetName(ci(2))) 
      Console.WriteLine("  {0,12}   {1,12}   {2,12}", _
                        value.ToString(ci(0)), value.ToString(ci(1)), value.ToString(ci(2)))            
      
   End Sub
   
   Private Function GetName(ci As CultureInfo) As String
      If ci.Equals(CultureInfo.InvariantCulture) Then
         Return "Invariant"
      Else
         Return ci.Name
      End If   
   End Function
End Module
' The example displays the following output:
'         en-US          fr-FR      Invariant
'         18924          18924          18924

설명

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

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

provider 매개 변수는 구현입니다IFormatProvider. 해당 GetFormat 메서드는 NumberFormatInfo 문화권별 서식 정보를 제공하는 개체를 반환합니다. 그러나 일반 숫자 형식 지정자("G")로 서식을 지정할 때 의 속성 NumberFormatInfo 은 사용되지 않습니다.

추가 정보

적용 대상

ToString(String)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.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 매개 변수가 잘못되었습니다.

예제

다음 예제에서는 각 표준 형식 문자열과 일부 사용자 지정 형식 문자열을 사용하여 16비트 부호 없는 정수 값을 표시합니다.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      ushort value = 21708;
      string[] specifiers = { "G", "C", "D3", "E2", "e3", "F", 
                              "N", "P", "X", "000000.0", "#.0", 
                              "00000000;(0);**Zero**" };
      
      foreach (string specifier in specifiers)
         Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));
   }
}
// The example displays the following output:
//       G: 21708
//       C: $21,708.00
//       D3: 21708
//       E2: 2.17E+004
//       e3: 2.171e+004
//       F: 21708.00
//       N: 21,708.00
//       P: 2,170,800.00 %
//       X: 54CC
//       000000.0: 021708.0
//       #.0: 21708.0
//       00000000;(0);**Zero**: 00021708
let value = 21708us
let specifiers = 
    [| "G"; "C"; "D3"; "E2"; "e3"; "F"
       "N"; "P"; "X"; "000000.0"; "#.0" 
       "00000000(0)**Zero**" |]

for specifier in specifiers do
    printfn $"{specifier}: {value.ToString specifier}"
// The example displays the following output:
//       G: 21708
//       C: $21,708.00
//       D3: 21708
//       E2: 2.17E+004
//       e3: 2.171e+004
//       F: 21708.00
//       N: 21,708.00
//       P: 2,170,800.00 %
//       X: 54CC
//       000000.0: 021708.0
//       #.0: 21708.0
//       00000000(0)**Zero**: 00021708
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim value As UShort = 21708 
      Dim specifiers() As String = { "G", "C", "D3", "E2", "e3", "F", _
                                     "N", "P", "X", "000000.0", "#.0", _
                                     "00000000;(0);**Zero**" }
      
      For Each specifier As String In specifiers
         Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
      Next
   End Sub
End Module
' The example displays the following output:
'       G: 21708
'       C: $21,708.00
'       D3: 21708
'       E2: 2.17E+004
'       e3: 2.171e+004
'       F: 21708.00
'       N: 21,708.00
'       P: 2,170,800.00 %
'       X: 54CC
'       000000.0: 021708.0
'       #.0: 21708.0
'       00000000;(0);**Zero**: 00021708

설명

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

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

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

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

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

추가 정보

적용 대상

ToString(String, IFormatProvider)

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.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 개체를 사용하여 16비트 부호 없는 정수 값을 표시합니다.

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") };
      string[] specifiers = {"G", "C", "D4", "E2", "F", "N", "P", "X2"}; 
      ushort value = 22042;
      
      foreach (string specifier in specifiers)
      {
         foreach (CultureInfo culture in cultures)
            Console.WriteLine("{0,2} format using {1} culture: {2, 16}",  
                              specifier, culture.Name, 
                              value.ToString(specifier, culture));
         Console.WriteLine();
      }
   }
}
// The example displays the following output:
//        G format using en-US culture:            22042
//        G format using fr-FR culture:            22042
//        G format using es-ES culture:            22042
//       
//        C format using en-US culture:       $22,042.00
//        C format using fr-FR culture:      22 042,00 €
//        C format using es-ES culture:      22.042,00 €
//       
//       D4 format using en-US culture:            22042
//       D4 format using fr-FR culture:            22042
//       D4 format using es-ES culture:            22042
//       
//       E2 format using en-US culture:        2.20E+004
//       E2 format using fr-FR culture:        2,20E+004
//       E2 format using es-ES culture:        2,20E+004
//       
//        F format using en-US culture:         22042.00
//        F format using fr-FR culture:         22042,00
//        F format using es-ES culture:         22042,00
//       
//        N format using en-US culture:        22,042.00
//        N format using fr-FR culture:        22 042,00
//        N format using es-ES culture:        22.042,00
//       
//        P format using en-US culture:   2,204,200.00 %
//        P format using fr-FR culture:   2 204 200,00 %
//        P format using es-ES culture:   2.204.200,00 %
//       
//       X2 format using en-US culture:             561A
//       X2 format using fr-FR culture:             561A
//       X2 format using es-ES culture:             561A
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 specifiers = [| "G"; "C"; "D4"; "E2"; "F"; "N"; "P"; "X2" |] 
let value = 22042us

for specifier in specifiers do
    for culture in cultures do
        printfn $"{specifier,2} format using {culture.Name} culture: {value.ToString(specifier, culture), 16}"
    printfn ""
// The example displays the following output:
//        G format using en-US culture:            22042
//        G format using fr-FR culture:            22042
//        G format using es-ES culture:            22042
//       
//        C format using en-US culture:       $22,042.00
//        C format using fr-FR culture:      22 042,00 €
//        C format using es-ES culture:      22.042,00 €
//       
//       D4 format using en-US culture:            22042
//       D4 format using fr-FR culture:            22042
//       D4 format using es-ES culture:            22042
//       
//       E2 format using en-US culture:        2.20E+004
//       E2 format using fr-FR culture:        2,20E+004
//       E2 format using es-ES culture:        2,20E+004
//       
//        F format using en-US culture:         22042.00
//        F format using fr-FR culture:         22042,00
//        F format using es-ES culture:         22042,00
//       
//        N format using en-US culture:        22,042.00
//        N format using fr-FR culture:        22 042,00
//        N format using es-ES culture:        22.042,00
//       
//        P format using en-US culture:   2,204,200.00 %
//        P format using fr-FR culture:   2 204 200,00 %
//        P format using es-ES culture:   2.204.200,00 %
//       
//       X2 format using en-US culture:             561A
//       X2 format using fr-FR culture:             561A
//       X2 format using es-ES culture:             561A
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 specifiers() As String = {"G", "C", "D4", "E2", "F", "N", "P", "X2"} 
      Dim value As UShort = 22042
      
      For Each specifier As String In specifiers
         For Each culture As CultureInfo In Cultures
            Console.WriteLine("{0,2} format using {1} culture: {2, 16}", _ 
                              specifier, culture.Name, _
                              value.ToString(specifier, culture))

         Next
         Console.WriteLine()
      Next
   End Sub
End Module
' The example displays the following output:
'        G format using en-US culture:            22042
'        G format using fr-FR culture:            22042
'        G format using es-ES culture:            22042
'       
'        C format using en-US culture:       $22,042.00
'        C format using fr-FR culture:      22 042,00 €
'        C format using es-ES culture:      22.042,00 €
'       
'       D4 format using en-US culture:            22042
'       D4 format using fr-FR culture:            22042
'       D4 format using es-ES culture:            22042
'       
'       E2 format using en-US culture:        2.20E+004
'       E2 format using fr-FR culture:        2,20E+004
'       E2 format using es-ES culture:        2,20E+004
'       
'        F format using en-US culture:         22042.00
'        F format using fr-FR culture:         22042,00
'        F format using es-ES culture:         22042,00
'       
'        N format using en-US culture:        22,042.00
'        N format using fr-FR culture:        22 042,00
'        N format using es-ES culture:        22.042,00
'       
'        P format using en-US culture:   2,204,200.00 %
'        P format using fr-FR culture:   2 204 200,00 %
'        P format using es-ES culture:   2.204.200,00 %
'       
'       X2 format using en-US culture:             561A
'       X2 format using fr-FR culture:             561A
'       X2 format using es-ES culture:             561A

설명

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

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

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

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

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

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

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

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

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

추가 정보

적용 대상

ToString()

Source:
UInt16.cs
Source:
UInt16.cs
Source:
UInt16.cs

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

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

반환

부호나 앞에 오는 0 없이 0에서 9 사이의 숫자 시퀀스로 구성된 이 인스턴스 값의 문자열 표현입니다.

예제

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

using System;

public class Example
{
   public static void Main()
   {
      ushort value = 16324;
      // Display value using default ToString method.
      Console.WriteLine(value.ToString());      
      Console.WriteLine();
      
      // Define an array of format specifiers.
      string[] formats = { "G", "C", "D", "F", "N", "X" };
      // Display value using the standard format specifiers.
      foreach (string format in formats)
         Console.WriteLine("{0} format specifier: {1,12}", 
                           format, value.ToString(format));         
   }
}
// The example displays the following output:
//       16324
//
//       G format specifier:        16324
//       C format specifier:   $16,324.00
//       D format specifier:        16324
//       F format specifier:     16324.00
//       N format specifier:    16,324.00
//       X format specifier:         3FC4
let value = 16324us
// Display value using default ToString method.
printfn $"{value.ToString()}\n"     

// Define an array of format specifiers.
let formats = [| "G"; "C"; "D"; "F"; "N"; "X" |]
// Display value using the standard format specifiers.
for format in formats do
    printfn $"{format} format specifier: {value.ToString format,12}" 
// The example displays the following output:
//       16324
//
//       G format specifier:        16324
//       C format specifier:   $16,324.00
//       D format specifier:        16324
//       F format specifier:     16324.00
//       N format specifier:    16,324.00
//       X format specifier:         3FC4
Module Example
   Public Sub Main()
      Dim value As UInt16 = 16324
      ' Display value using default ToString method.
      Console.WriteLine(value.ToString())            
      Console.WriteLine()
      
      ' Define an array of format specifiers.
      Dim formats() As String = { "G", "C", "D", "F", "N", "X" }
      ' Display value using the standard format specifiers.
      For Each format As String In formats
         Console.WriteLine("{0} format specifier: {1,12}", _
                           format, value.ToString(format))         
      Next
   End Sub
End Module
' The example displays the following output:
'       16324
'       
'       G format specifier:        16324
'       C format specifier:   $16,324.00
'       D format specifier:        16324
'       F format specifier:     16324.00
'       N format specifier:    16,324.00
'       X format specifier:         3FC4

설명

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

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

추가 정보

적용 대상