Clone Method
Collapse the table of content
Expand the table of content

CultureInfo.Clone Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft