Share via


グローバルな Windows フォームおよび Web フォームにおけるカルチャ固有のクラス

更新 : 2007 年 11 月

日付、時刻、数値、通貨などの情報の表示には、地域ごとに異なる規則があります。System.Globalization 名前空間を使用すると、DateTimeFormatInfo、Calendar、NumberFormatInfo など、カルチャ固有の値の表示形式を変更できます。

カルチャ設定の使用

しかし、実行時に表記規則を自動的に判断し、それに応じた形式の情報を表示させる場合は、アプリケーションに保存されたカルチャ設定またはコントロール パネルの [地域のオプション] に保存されたカルチャの設定を使用するのが一般的です。カルチャ設定の詳細については、「方法 : Windows フォームのグローバリゼーション用のカルチャおよび UI カルチャを設定する」または「方法 : ASP.NET Web ページのグローバリゼーション用のカルチャおよび UI カルチャを設定する」を参照してください。カルチャに応じて自動的に情報の形式が決まるクラスをカルチャ固有のクラスといいます。カルチャ固有のメソッドとしては、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

参照

参照

MonthName 関数 (Visual Basic)

WeekdayName 関数 (Visual Basic)

IFormattable.ToString

DateTimeFormatInfo

NumberFormatInfo

Calendar

Console.WriteLine

String.Format

その他の技術情報

アプリケーションのグローバライズとローカライズ