当前位置: 首页>>代码示例>>C#>>正文


C# UInt16.ToString方法代码示例

本文整理汇总了C#中System.UInt16.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# UInt16.ToString方法的具体用法?C# UInt16.ToString怎么用?C# UInt16.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。


在下文中一共展示了UInt16.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 }; 
      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;         
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:27,代码来源:UInt16.ToString

输出:

en-US          fr-FR      Invariant
18924          18924          18924

示例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"}; 
      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();
      }
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:25,代码来源:UInt16.ToString

输出:

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

示例3: Main

//引入命名空间
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));
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:17,代码来源:UInt16.ToString

输出:

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

示例4: Main

//引入命名空间
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));         
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:20,代码来源:UInt16.ToString

输出:

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

示例5: UInt16.ToString()

//引入命名空间
using System;

class MainClass
{
    public static void Main(string[] args)
    {
    System.UInt16 myUInt16 = 30000;
    Console.WriteLine("Your value is: {0}", myUInt16.ToString());
    Console.WriteLine("I am a: {0}", myUInt16.GetType().ToString());
    }

}
开发者ID:C#程序员,项目名称:System,代码行数:13,代码来源:UInt16.ToString


注:本文中的System.UInt16.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。