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


C# UInt64.ToString方法代碼示例

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


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

示例1: Main

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

輸出:

en-US          fr-FR      Invariant
18709243       18709243       18709243

示例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") };
      string[] specifiers = {"G", "C", "D4", "E2", "F", "N", "P", "X2"}; 
      ulong value = 22224021;
      
      foreach (string specifier in specifiers)
      {
         foreach (CultureInfo culture in cultures)
            Console.WriteLine("{0,2} format using {1} culture: {2, 18}",  
                              specifier, culture.Name, 
                              value.ToString(specifier, culture));
         Console.WriteLine();
      }
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:25,代碼來源:UInt64.ToString

輸出:

G format using en-US culture:           22224021
G format using fr-FR culture:           22224021
G format using es-ES culture:           22224021

C format using en-US culture:     $22,224,021.00
C format using fr-FR culture:    22 224 021,00 ?
C format using es-ES culture:    22.224.021,00 ?

D4 format using en-US culture:           22224021
D4 format using fr-FR culture:           22224021
D4 format using es-ES culture:           22224021

E2 format using en-US culture:          2.22E+007
E2 format using fr-FR culture:          2,22E+007
E2 format using es-ES culture:          2,22E+007

F format using en-US culture:        22224021.00
F format using fr-FR culture:        22224021,00
F format using es-ES culture:        22224021,00

N format using en-US culture:      22,224,021.00
N format using fr-FR culture:      22 224 021,00
N format using es-ES culture:      22.224.021,00

P format using en-US culture: 2,222,402,100.00 %
P format using fr-FR culture: 2 222 402 100,00 %
P format using es-ES culture: 2.222.402.100,00 %

X2 format using en-US culture:            1531C95
X2 format using fr-FR culture:            1531C95
X2 format using es-ES culture:            1531C95

示例3: Main

//引入命名空間
using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      ulong value = 217960834;
      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));
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:17,代碼來源:UInt64.ToString

輸出:

G: 217960834
C: $217,960,834.00
D3: 217960834
E2: 2.18E+008
e3: 2.180e+008
F: 217960834.00
N: 217,960,834.00
P: 21,796,083,400.00 %
X: CFDD182
000000.0: 217960834.0
#.0: 217960834.0
00000000;(0);**Zero**: 217960834

示例4: Main

//引入命名空間
using System;

public class Example
{
   public static void Main()
   {
      ulong value = 163249057;
      // 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,16}", 
                           format, value.ToString(format));         
   }
}
開發者ID:.NET開發者,項目名稱:System,代碼行數:20,代碼來源:UInt64.ToString

輸出:

163249057

G format specifier:        163249057
C format specifier:  $163,249,057.00
D format specifier:        163249057
F format specifier:     163249057.00
N format specifier:   163,249,057.00
X format specifier:          9BAFBA1


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