NumberFormatInfo.IsReadOnly 属性

定义

获取一个值,该值指示 NumberFormatInfo 对象是否为只读。

public:
 property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean

属性值

如果 true 是只读的,则为 NumberFormatInfo;否则为 false

注解

尝试对 只读 NumberFormatInfo 属性执行赋值会导致 InvalidOperationException

可以调用 Clone 方法从只读对象创建读/写 NumberFormatInfo 对象,如以下示例所示。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      NumberFormatInfo nfi = NumberFormatInfo.CurrentInfo;
      Console.WriteLine("Read-Only: {0}\n", nfi.IsReadOnly);

      NumberFormatInfo nfiw = (NumberFormatInfo) nfi.Clone();
      Console.WriteLine("Read-Only: {0}", nfiw.IsReadOnly);
   }
}
// The example displays the following output:
//       Read-Only: True
//
//       Read-Only: False
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim nfi As NumberFormatInfo = NumberFormatInfo.CurrentInfo
      Console.WriteLine("Read-Only: {0}", nfi.IsReadOnly)
      Console.WriteLine()
      Dim nfiw As NumberFormatInfo = CType(nfi.Clone(), NumberFormatInfo)
      Console.WriteLine("Read-Only: {0}", nfiw.IsReadOnly)
   End Sub
End Module
' The example displays the following output:
'       Read-Only: True
'       
'       Read-Only: False

适用于

另请参阅