Freigeben über


CultureInfo.ReadOnly-Methode

Gibt einen schreibgeschützten Wrapper für die angegebene CultureInfo zurück.

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

Syntax

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

returnValue = CultureInfo.ReadOnly(ci)
public static CultureInfo ReadOnly (
    CultureInfo ci
)
public:
static CultureInfo^ ReadOnly (
    CultureInfo^ ci
)
public static CultureInfo ReadOnly (
    CultureInfo ci
)
public static function ReadOnly (
    ci : CultureInfo
) : CultureInfo

Parameter

Rückgabewert

Ein schreibgeschützter CultureInfo-Wrapper um ci.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentNullException

ci ist NULL (Nothing in Visual Basic).

Hinweise

Dieser Wrapper verhindert Änderungen an ci oder den Objekten, die von der ci.DateTimeFormat-Eigenschaft und der ci.NumberFormat-Eigenschaft zurückgegeben werden.

Beispiel

Folgender Beispielcode zeigt, dass mit der ReadOnly-Methode die CultureInfo zugeordneten Instanzen DateTimeFormatInfo und NumberFormatInfo geschützt werden können.

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

*/
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.
*/
import System.* ;
import System.Globalization.* ;

public class SamplesCultureInfo
{
    public static void main(String[] args)
    {
        // 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.get_IsReadOnly() ) ? "read only" : "writable");
        Console.WriteLine("myCI.DateTimeFormat is {0}.",
            (myCI.get_DateTimeFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
        Console.WriteLine("myCI.NumberFormat is {0}.",(
            myCI.get_NumberFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
        Console.WriteLine("myReadOnlyCI is {0}.",
            (myReadOnlyCI.get_IsReadOnly()) ? "read only" : "writable");
        Console.WriteLine("myReadOnlyCI.DateTimeFormat is {0}.",
            (myReadOnlyCI.get_DateTimeFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
        Console.WriteLine("myReadOnlyCI.NumberFormat is {0}.",
            (myReadOnlyCI.get_NumberFormat().get_IsReadOnly()) ? 
            "read only" : "writable");
    } //main 
} //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.
*/

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

CultureInfo-Klasse
CultureInfo-Member
System.Globalization-Namespace
IsReadOnly