CultureInfo.OptionalCalendars プロパティ

カルチャで使用できる暦の一覧を取得します。

Public Overridable ReadOnly Property OptionalCalendars As Calendar _   ()
[C#]
public virtual Calendar[] OptionalCalendars {get;}
[C++]
public: __property virtual Calendar* get_OptionalCalendars();
[JScript]
public function get OptionalCalendars() : Calendar[];

プロパティ値

現在の CultureInfo が表すカルチャで使用できる暦を表す Calendar 型の配列。

解説

現在の CultureInfo で使用される暦は、 DateTimeFormatInfo クラスのインスタンスである DateTimeFormatCalendar プロパティを設定することにより変更できます。新しい暦は、 OptionalCalendars に挙げられている暦の 1 つである必要があります。 DateTimeFormat には、 Calendar に関連付けられた日付と時刻の形式をカスタマイズするその他のプロパティも含まれます。

使用例

[Visual Basic, C#, C++] カルチャによってサポートされている GregorianCalendar のバージョンを判断する方法を示すコードの例を次に示します。

 
Imports System
Imports System.Globalization

Public Class SamplesCultureInfo

   Public Shared Sub Main()

      ' Gets the calendars supported by the ar-SA culture.
      Dim myOptCals As Calendar() = New CultureInfo("ar-SA").OptionalCalendars

      ' Checks which ones are GregorianCalendar then determines the GregorianCalendar version.
      Console.WriteLine("The ar-SA culture supports the following calendars:")
      Dim cal As Calendar
      For Each cal In  myOptCals
         If cal.GetType() Is GetType(GregorianCalendar)  Then
            Dim myGreCal As GregorianCalendar = CType(cal, GregorianCalendar)
            Dim calType As GregorianCalendarTypes = myGreCal.CalendarType
            Console.WriteLine("   {0} ({1})", cal, calType)
         Else
            Console.WriteLine("   {0}", cal)
         End If
      Next cal

   End Sub 'Main 

End Class 'SamplesCultureInfo


'This code produces the following output.
'
'The ar-SA culture supports the following calendars:
'   System.Globalization.HijriCalendar
'   System.Globalization.GregorianCalendar (USEnglish)
'   System.Globalization.GregorianCalendar (MiddleEastFrench)
'   System.Globalization.GregorianCalendar (Arabic)
'   System.Globalization.GregorianCalendar (Localized)
'   System.Globalization.GregorianCalendar (TransliteratedFrench)


[C#] 
using System;
using System.Globalization;


public class SamplesCultureInfo  {

   public static void Main()  {

      // Gets the calendars supported by the ar-SA culture.
      Calendar[] myOptCals = new CultureInfo("ar-SA").OptionalCalendars;

      // Checks which ones are GregorianCalendar then determines the GregorianCalendar version.
      Console.WriteLine( "The ar-SA culture supports the following calendars:" );
      foreach ( Calendar cal in myOptCals )  {
         if ( cal.GetType() == typeof( GregorianCalendar ) )  {
            GregorianCalendar myGreCal = (GregorianCalendar) cal;
            GregorianCalendarTypes calType = myGreCal.CalendarType;
            Console.WriteLine( "   {0} ({1})", cal, calType );
         }
         else  {
            Console.WriteLine( "   {0}", cal );
         }
      }

   }

}

/*
This code produces the following output.

The ar-SA culture supports the following calendars:
   System.Globalization.HijriCalendar
   System.Globalization.GregorianCalendar (USEnglish)
   System.Globalization.GregorianCalendar (MiddleEastFrench)
   System.Globalization.GregorianCalendar (Arabic)
   System.Globalization.GregorianCalendar (Localized)
   System.Globalization.GregorianCalendar (TransliteratedFrench)

*/

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
using namespace System::Collections;

int main()
{
   // Calendar* myOptCals[] = new CultureInfo(S"ar-SA") -> OptionalCalendars;
   CultureInfo * MyCI = new CultureInfo(S"ar-SA");
   Calendar* myOptCals[] = MyCI -> OptionalCalendars;

   // Checks which ones are GregorianCalendar then determines the GregorianCalendar version.
   Console::WriteLine(S"The ar-SA culture supports the following calendars:");
   IEnumerator* myEnum = myOptCals->GetEnumerator();
   while (myEnum->MoveNext())
   {
      Calendar* cal = __try_cast<Calendar*>(myEnum->Current);
      if (cal -> GetType() == __typeof(GregorianCalendar))
      {
         GregorianCalendar * myGreCal = dynamic_cast<GregorianCalendar*>(cal);
         GregorianCalendarTypes calType = myGreCal -> CalendarType;
         Console::WriteLine(S" {0} ( {1})", cal, __box(calType));
      }
      else
         Console::WriteLine(S" {0}", cal);
   }
}

/*
This code produces the following output.

The ar-SA culture supports the following calendars:
 System.Globalization.HijriCalendar
 System.Globalization.GregorianCalendar ( USEnglish)
 System.Globalization.GregorianCalendar ( MiddleEastFrench)
 System.Globalization.GregorianCalendar ( Arabic)
 System.Globalization.GregorianCalendar ( Localized)
 System.Globalization.GregorianCalendar ( TransliteratedFrench)

*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

CultureInfo クラス | CultureInfo メンバ | System.Globalization 名前空間 | Calendar | DateTimeFormat | DateTimeFormatInfo