Share via


全域 Windows Form 和 Web Form 的文化特性特定類別

每種文化都具有不同的慣例來顯示日期、時間、數字、貨幣和其他資訊。 System.Globalization 命名空間所包含的類別,可以用於修改文化特性特定值顯示的方式,例如 DateTimeFormatInfo、[月曆] 和 NumberFormatInfo

使用文化特性設定

然而多數時候您都將使用儲存於應用程式中或 [地區選項] 控制台中的文化特性設定,在執行階段時自動決定慣例,並依照該慣例格式化資訊。 如需設定文化特性的詳細資訊,請參閱 HOW TO:設定 Windows Form 全球化的文化特性和 UI 文化特性How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization。 依據文化特性設定自動格式化資訊的類別稱為文化特性特定。 某些文化特性特定的方法包括 IFormattable.ToStringConsole.WriteLineString.Format。 文化特性特定函式 (在 Visual Basic 語言中) 的例子有 MonthName 和 WeekDayName。

例如,下列程式碼顯示如何使用 ToString 方法來針對目前的文化特性格式化貨幣:

' Put the Imports statements at the beginning of the code module
Imports System.Threading
Imports System.Globalization
' Display a number with the culture-specific currency formatting
Dim MyInt As Integer = 100
Console.WriteLine(MyInt.ToString("C", Thread.CurrentThread.CurrentCulture))
// Put the using statements at the beginning of the code module
using System.Threading;
using System.Globalization;
// Display a number with the culture-specific currency formatting
int myInt = 100;
Console.WriteLine(myInt.ToString("C", Thread.CurrentThread.CurrentCulture));

如果文化特性是設定為 "fr-FR",您會在輸出視窗看到下列格式:

100,00

如果文化特性是設定為 "en-US",您會在輸出視窗看到下列格式:

$100.00

請參閱

參考

IFormattable.ToString

DateTimeFormatInfo

NumberFormatInfo

Calendar

Console.WriteLine

String.Format

其他資源

全球化和當地語系化應用程式