共用方式為


CultureInfo.ReadOnly(CultureInfo) 方法

定義

傳回指定 CultureInfo 物件的唯讀包裝函式。

public:
 static System::Globalization::CultureInfo ^ ReadOnly(System::Globalization::CultureInfo ^ ci);
public static System.Globalization.CultureInfo ReadOnly (System.Globalization.CultureInfo ci);
static member ReadOnly : System.Globalization.CultureInfo -> System.Globalization.CultureInfo
Public Shared Function ReadOnly (ci As CultureInfo) As CultureInfo

參數

ci
CultureInfo

要包裝的 CultureInfo 物件。

傳回

ci 的唯讀 CultureInfo 包裝函式。

例外狀況

ci 為 null。

範例

下列範例顯示 方法有助於ReadOnly保護DateTimeFormatInfo與 相關聯的 CultureInfoNumberFormatInfo 實例。

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates a CultureInfo.
   CultureInfo^ myCI = gcnew 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.
   Console::WriteLine( "myCI is {0}.", myCI->IsReadOnly ? (String^)"read only" : "writable" );
   Console::WriteLine( "myCI -> DateTimeFormat is {0}.", myCI->DateTimeFormat->IsReadOnly ? (String^)"read only" : "writable" );
   Console::WriteLine( "myCI -> NumberFormat is {0}.", myCI->NumberFormat->IsReadOnly ? (String^)"read only" : "writable" );
   Console::WriteLine( "myReadOnlyCI is {0}.", myReadOnlyCI->IsReadOnly ? (String^)"read only" : "writable" );
   Console::WriteLine( "myReadOnlyCI -> DateTimeFormat is {0}.", myReadOnlyCI->DateTimeFormat->IsReadOnly ? (String^)"read only" : "writable" );
   Console::WriteLine( "myReadOnlyCI -> NumberFormat is {0}.", myReadOnlyCI->NumberFormat->IsReadOnly ? (String^)"read only" : "writable" );
}

/*
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 SamplesCultureInfo  {

   public static void Main()  {

      // 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.
      Console.WriteLine( "myCI is {0}.", myCI.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myCI.DateTimeFormat is {0}.", myCI.DateTimeFormat.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myCI.NumberFormat is {0}.", myCI.NumberFormat.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myReadOnlyCI is {0}.", myReadOnlyCI.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myReadOnlyCI.DateTimeFormat is {0}.", myReadOnlyCI.DateTimeFormat.IsReadOnly ? "read only" : "writable" );
      Console.WriteLine( "myReadOnlyCI.NumberFormat is {0}.", myReadOnlyCI.NumberFormat.IsReadOnly ? "read only" : "writable" );
   }
}

/*
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.

*/
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

End Class


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

備註

這個包裝函式可防止對 的任何修改ci,或 由和DateTimeFormatciNumberFormatci回的物件。

適用於

另請參閱