當前位置: 首頁>>代碼示例>>C#>>正文


C# SByte.ToString方法代碼示例

本文整理匯總了C#中System.SByte.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# SByte.ToString方法的具體用法?C# SByte.ToString怎麽用?C# SByte.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了SByte.ToString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

//引入命名空間
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));
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:28,代碼來源:SByte.ToString

輸出:

Using the custom NumberFormatInfo object:
~122
17
124

Using the invariant culture:
-122
17
124

示例2: Main

//引入命名空間
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();
      }
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:27,代碼來源:SByte.ToString

輸出:

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

示例3: Main

//引入命名空間
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();
      }
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:21,代碼來源:SByte.ToString

輸出:

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

示例4: Main

//引入命名空間
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
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:19,代碼來源:SByte.ToString


注:本文中的System.SByte.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。