本文整理汇总了C#中System.UInt32.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# UInt32.ToString方法的具体用法?C# UInt32.ToString怎么用?C# UInt32.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了UInt32.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 };
uint value = 1870924;
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;
}
}
输出:
en-US fr-FR Invariant 1870924 1870924 1870924
示例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"};
uint value = 2222402;
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();
}
}
}
输出:
G format using en-US culture: 2222402 G format using fr-FR culture: 2222402 G format using es-ES culture: 2222402 C format using en-US culture: $2,222,402.00 C format using fr-FR culture: 2 222 402,00 € C format using es-ES culture: 2.222.402,00 € D4 format using en-US culture: 2222402 D4 format using fr-FR culture: 2222402 D4 format using es-ES culture: 2222402 E2 format using en-US culture: 2.22E+006 E2 format using fr-FR culture: 2,22E+006 E2 format using es-ES culture: 2,22E+006 F format using en-US culture: 2222402.00 F format using fr-FR culture: 2222402,00 F format using es-ES culture: 2222402,00 N format using en-US culture: 2,222,402.00 N format using fr-FR culture: 2 222 402,00 N format using es-ES culture: 2.222.402,00 P format using en-US culture: 222,240,200.00 % P format using fr-FR culture: 222 240 200,00 % P format using es-ES culture: 222.240.200,00 % X2 format using en-US culture: 21E942 X2 format using fr-FR culture: 21E942 X2 format using es-ES culture: 21E942
示例3: Main
//引入命名空间
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
uint value = 2179608;
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));
}
}
输出:
G: 2179608 C: $2,179,608.00 D3: 2179608 E2: 2.18E+006 e3: 2.180e+006 F: 2179608.00 N: 2,179,608.00 P: 217,960,800.00 % X: 214218 000000.0: 2179608.0 #.0: 2179608.0 00000000;(0);**Zero**: 02179608
示例4: Main
//引入命名空间
using System;
public class Example
{
public static void Main()
{
uint value = 1632490;
// 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));
}
}
输出:
1632490 G format specifier: 1632490 C format specifier: $1,632,490.00 D format specifier: 1632490 F format specifier: 1632490.00 N format specifier: 1,632,490.00 X format specifier: 18E8EA