Export (0) Print
Expand All

CultureInfo.IsReadOnly Property

Gets a value indicating whether the current CultureInfo is read-only.

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)

public bool IsReadOnly { get; }
/** @property */
public boolean get_IsReadOnly ()

public function get IsReadOnly () : boolean

Not applicable.

Property Value

true if the current CultureInfo is read-only; otherwise, false. The default is false.

If the CultureInfo is read-only, the DateTimeFormat and NumberFormat instances are also read-only.

The following code example shows that IsReadOnly also helps protect the DateTimeFormatInfo and NumberFormatInfo instances associated with the CultureInfo.

using System;
using System.Globalization;


public class SamplesCultureInfo  {

   public static void Main()  {

      // Creates a CultureInfo.
      CultureInfo myCI = new CultureInfo( "en-US" );

      // Creates a read-only CultureInfo based on myCI.
      CultureInfo myReadOnlyCI = CultureInfo.ReadOnly( myCI );

      // Display the read-only status of each CultureInfo and their DateTimeFormat and NumberFormat properties.
      Console.WriteLine( "myCI is {0}.", myCI.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myCI.DateTimeFormat is {0}.", myCI.DateTimeFormat.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myCI.NumberFormat is {0}.", myCI.NumberFormat.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myReadOnlyCI is {0}.", myReadOnlyCI.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myReadOnlyCI.DateTimeFormat is {0}.", myReadOnlyCI.DateTimeFormat.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myReadOnlyCI.NumberFormat is {0}.", myReadOnlyCI.NumberFormat.IsReadOnly ? "read only" : "writable" );

   }

}

/*
This code produces the following output.

myCI is writable.
myCI.DateTimeFormat is writable.
myCI.NumberFormat is writable.
myReadOnlyCI is read only.
myReadOnlyCI.DateTimeFormat is read only.
myReadOnlyCI.NumberFormat is read only.

*/

import System.* ;
import System.Globalization.* ;

public class SamplesCultureInfo
{
    public static void main(String[] args)
    {
        // Creates a CultureInfo.
        CultureInfo myCI =  new CultureInfo("en-US");

        // Creates a read-only CultureInfo based on myCI.
        CultureInfo myReadOnlyCI = CultureInfo.ReadOnly(myCI);

        // Display the read-only status of each CultureInfo and their 
        // DateTimeFormat and NumberFormat properties.
        Console.WriteLine("myCI is {0}.",
            (myCI.get_IsReadOnly() ) ? "read only" : "writable");
        Console.WriteLine("myCI.DateTimeFormat is {0}.",
            (myCI.get_DateTimeFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
        Console.WriteLine("myCI.NumberFormat is {0}.",(
            myCI.get_NumberFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
        Console.WriteLine("myReadOnlyCI is {0}.",
            (myReadOnlyCI.get_IsReadOnly()) ? "read only" : "writable");
        Console.WriteLine("myReadOnlyCI.DateTimeFormat is {0}.",
            (myReadOnlyCI.get_DateTimeFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
        Console.WriteLine("myReadOnlyCI.NumberFormat is {0}.",
            (myReadOnlyCI.get_NumberFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
    } //main 
} //SamplesCultureInfo

/*
This code produces the following output.

myCI is writable.
myCI.DateTimeFormat is writable.
myCI.NumberFormat is writable.
myReadOnlyCI is read only.
myReadOnlyCI.DateTimeFormat is read only.
myReadOnlyCI.NumberFormat is read only.
*/

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft