Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

CultureInfo.IsReadOnly Property

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

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

public bool IsReadOnly { get; }

Property Value

Type: System.Boolean
true if the current CultureInfo object is read-only; otherwise, false. The default is false.

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

To create a read/write copy of a read-only CultureInfo object, call the Clone method. To create a read-only wrapper for a writable CultureInfo object, call the ReadOnly method.

The following example shows that IsReadOnly also helps protect the DateTimeFormatInfo and NumberFormatInfo objects that are associated with the CultureInfo object.


using System;
using System.Globalization;


public class Example
{

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      // 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.
      outputBlock.Text += String.Format("myCI is {0}.", myCI.IsReadOnly ? "read only" : "writable") + "\n";
      outputBlock.Text += String.Format("myCI.DateTimeFormat is {0}.", myCI.DateTimeFormat.IsReadOnly ? "read only" : "writable") + "\n";
      outputBlock.Text += String.Format("myCI.NumberFormat is {0}.", myCI.NumberFormat.IsReadOnly ? "read only" : "writable") + "\n";
      outputBlock.Text += String.Format("myReadOnlyCI is {0}.", myReadOnlyCI.IsReadOnly ? "read only" : "writable") + "\n";
      outputBlock.Text += String.Format("myReadOnlyCI.DateTimeFormat is {0}.", myReadOnlyCI.DateTimeFormat.IsReadOnly ? "read only" : "writable") + "\n";
      outputBlock.Text += String.Format("myReadOnlyCI.NumberFormat is {0}.", myReadOnlyCI.NumberFormat.IsReadOnly ? "read only" : "writable") + "\n";

   }

}

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

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2015 Microsoft