ReadOnly Method
Collapse the table of content
Expand the table of content

CultureInfo.ReadOnly Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Returns a read-only wrapper around the specified CultureInfo object.

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

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

Parameters

ci
Type: System.Globalization.CultureInfo
The CultureInfo object 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 example shows that the ReadOnly method helps protect the DateTimeFormatInfo and NumberFormatInfo instances associated with the CultureInfo.


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.


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft