This documentation is archived and is not being maintained.

CultureInfo.ReadOnly Method

Returns a read-only wrapper around the specified CultureInfo.

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

'Declaration
Public Shared Function ReadOnly ( _
	ci As CultureInfo _
) As CultureInfo
'Usage
Dim ci As CultureInfo 
Dim returnValue As CultureInfo 

returnValue = CultureInfo.ReadOnly(ci)

Parameters

ci
Type: System.Globalization.CultureInfo

The CultureInfo to wrap.

Return Value

Type: System.Globalization.CultureInfo
A read-only CultureInfo wrapper around ci.

ExceptionCondition
ArgumentNullException

ci is null.

This wrapper prevents any modifications to ci, or the objects returned by the ci.DateTimeFormat and ci.NumberFormat properties.

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

Imports System
Imports System.Globalization


Public Class SamplesCultureInfo

   Public Shared Sub Main()

      ' 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 
         Console.WriteLine("myCI is read only.")
      Else
         Console.WriteLine("myCI is writable.")
      End If 

      If myCI.DateTimeFormat.IsReadOnly Then 
         Console.WriteLine("myCI.DateTimeFormat is read only.")
      Else
         Console.WriteLine("myCI.DateTimeFormat is writable.")
      End If 

      If myCI.NumberFormat.IsReadOnly Then 
         Console.WriteLine("myCI.NumberFormat is read only.")
      Else
         Console.WriteLine("myCI.NumberFormat is writable.")
      End If 

      If myReadOnlyCI.IsReadOnly Then 
         Console.WriteLine("myReadOnlyCI is read only.")
      Else
         Console.WriteLine("myReadOnlyCI is writable.")
      End If 

      If myReadOnlyCI.DateTimeFormat.IsReadOnly Then 
         Console.WriteLine("myReadOnlyCI.DateTimeFormat is read only.")
      Else
         Console.WriteLine("myReadOnlyCI.DateTimeFormat is writable.")
      End If 

      If myReadOnlyCI.NumberFormat.IsReadOnly Then 
         Console.WriteLine("myReadOnlyCI.NumberFormat is read only.")
      Else
         Console.WriteLine("myReadOnlyCI.NumberFormat is writable.")
      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.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show: