Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

CultureInfo.OptionalCalendars Property

Definition

Namespace:
System.Globalization
Assemblies:
mscorlib.dll, System.Globalization.dll
Assemblies:
netstandard.dll, System.Runtime.dll
Assembly:
System.Globalization.dll
Assembly:
System.Runtime.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
CultureInfo.cs
Source:
CultureInfo.cs
Source:
CultureInfo.cs
Source:
CultureInfo.cs
Source:
CultureInfo.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets the list of calendars that can be used by the culture.

public:
 virtual property cli::array <System::Globalization::Calendar ^> ^ OptionalCalendars { cli::array <System::Globalization::Calendar ^> ^ get(); };
public virtual System.Globalization.Calendar[] OptionalCalendars { get; }
member this.OptionalCalendars : System.Globalization.Calendar[]
Public Overridable ReadOnly Property OptionalCalendars As Calendar()

Property Value

An array of type Calendar that represents the calendars that can be used by the culture represented by the current CultureInfo.

Examples

The following code example demonstrates how to determine the GregorianCalendar versions supported by the culture.

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)

*/
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

End Class


'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)

Remarks

Your application changes the calendar used by the current CultureInfo by setting the Calendar property of DateTimeFormat, which is an instance of the DateTimeFormatInfo class. The new calendar must be one of the calendars listed in OptionalCalendars. DateTimeFormat also includes other properties that customize the date and time formatting associated with that Calendar.

Applies to

See also


Feedback

Was this page helpful?