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.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- ci
- Type: System.Globalization.CultureInfo
The CultureInfo object to wrap.
| Exception | Condition |
|---|---|
| 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.
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. */