Share via


CultureInfo.IsReadOnly Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public ReadOnly Property IsReadOnly As Boolean
public bool IsReadOnly { get; }

Property Value

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

Remarks

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.

Examples

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

Imports System.Globalization


Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Creates a CultureInfo.
      Dim myCI As New CultureInfo("en-US")

      ' Creates a read-only CultureInfo based on myCI.
      Dim myReadOnlyCI As CultureInfo = CultureInfo.ReadOnly(myCI)

      ' Display the read-only status of each CultureInfo and their DateTimeFormat and NumberFormat properties.
      If myCI.IsReadOnly Then
         outputBlock.Text &= "myCI is read only." & vbCrLf
      Else
         outputBlock.Text &= "myCI is writable." & vbCrLf
      End If

      If myCI.DateTimeFormat.IsReadOnly Then
         outputBlock.Text &= "myCI.DateTimeFormat is read only." & vbCrLf
      Else
         outputBlock.Text &= "myCI.DateTimeFormat is writable." & vbCrLf
      End If

      If myCI.NumberFormat.IsReadOnly Then
         outputBlock.Text &= "myCI.NumberFormat is read only." & vbCrLf
      Else
         outputBlock.Text &= "myCI.NumberFormat is writable." & vbCrLf
      End If

      If myReadOnlyCI.IsReadOnly Then
         outputBlock.Text &= "myReadOnlyCI is read only." & vbCrLf
      Else
         outputBlock.Text &= "myReadOnlyCI is writable." & vbCrLf
      End If

      If myReadOnlyCI.DateTimeFormat.IsReadOnly Then
         outputBlock.Text &= "myReadOnlyCI.DateTimeFormat is read only." & vbCrLf
      Else
         outputBlock.Text &= "myReadOnlyCI.DateTimeFormat is writable." & vbCrLf
      End If

      If myReadOnlyCI.NumberFormat.IsReadOnly Then
         outputBlock.Text &= "myReadOnlyCI.NumberFormat is read only." & vbCrLf
      Else
         outputBlock.Text &= "myReadOnlyCI.NumberFormat is writable." & vbCrLf
      End If

   End Sub 'Main 

End Class '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.
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.

*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.