Export (0) Print
Expand All

CultureInfo.Clone Method

Creates a copy of the current CultureInfo object.

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

'Declaration
Public Overridable Function Clone As Object

Return Value

Type: System.Object
A copy of the current CultureInfo object.

The Clone method creates a copy of the original object whose IsReadOnly method always returns false. This means that the clone is writable even if the original CultureInfo object is read-only. Therefore, the properties of the clone can be modified.

The Clone method creates an enhanced shallow copy. This means that, in addition to creating a copy of the original CultureInfo object, the method also creates copies of the objects returned by the NumberFormat, DateTimeFormat, TextInfo, and Calendar properties. Consequently, the cloned CultureInfo object can modify its copied properties without affecting the original CultureInfo object. (Most Clone methods return a shallow copy only. A shallow copy copies the current object but does not create copies of any objects returned by the current object's members. Instead, it refers to the original objects.)

The following example shows that Clone also clones 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 and initializes a CultureInfo object.
      Dim myCI As New CultureInfo("en-US")

      ' Clones myCI and modifies the DTFI and NFI instances associated with the clone.
      Dim myCIclone As CultureInfo = CType(myCI.Clone(), CultureInfo)
      myCIclone.DateTimeFormat.AMDesignator = "a.m."
      myCIclone.NumberFormat.CurrencySymbol = "USD"
      myCIclone.NumberFormat.NumberDecimalDigits = 4

      ' Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
      outputBlock.Text &= "DTFI/NFI PROPERTY" + ControlChars.Tab + "ORIGINAL" + ControlChars.Tab + "MODIFIED CLONE" & vbCrLf
      outputBlock.Text += String.Format("DTFI.AMDesignator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator) & vbCrLf
      outputBlock.Text += String.Format("NFI.CurrencySymbol" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol) & vbCrLf
      outputBlock.Text += String.Format("NFI.NumberDecimalDigits" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits) & vbCrLf
   End Sub  

End Class 
' This example produces the following output.
'       DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
'       DTFI.AMDesignator       AM              a.m.
'       NFI.CurrencySymbol      $               USD
'       NFI.NumberDecimalDigits 2               4


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft