CultureInfo.Clone メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の CultureInfo のコピーを作成します。
public:
virtual System::Object ^ Clone();
public virtual object Clone ();
abstract member Clone : unit -> obj
override this.Clone : unit -> obj
Public Overridable Function Clone () As Object
現在の CultureInfo のコピー。
次のコード例は、CultureInfo.Clone によって、 に関連付けられている CultureInfoインスタンスと NumberFormatInfo インスタンスも複製DateTimeFormatInfoされることを示しています。
using namespace System;
using namespace System::Globalization;
int main()
{
// Creates and initializes a CultureInfo.
CultureInfo^ myCI = gcnew CultureInfo( "en-US",false );
// Clones myCI and modifies the DTFI and NFI instances associated with the clone.
CultureInfo^ myCIclone = dynamic_cast<CultureInfo^>(myCI->Clone());
myCIclone->DateTimeFormat->AMDesignator = "a.m.";
myCIclone->DateTimeFormat->DateSeparator = "-";
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.
Console::WriteLine( "DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE" );
Console::WriteLine( "DTFI.AMDesignator\t{0}\t\t{1}", myCI->DateTimeFormat->AMDesignator, myCIclone->DateTimeFormat->AMDesignator );
Console::WriteLine( "DTFI.DateSeparator\t{0}\t\t{1}", myCI->DateTimeFormat->DateSeparator, myCIclone->DateTimeFormat->DateSeparator );
Console::WriteLine( "NFI.CurrencySymbol\t{0}\t\t{1}", myCI->NumberFormat->CurrencySymbol, myCIclone->NumberFormat->CurrencySymbol );
Console::WriteLine( "NFI.NumberDecimalDigits\t{0}\t\t{1}", myCI->NumberFormat->NumberDecimalDigits, myCIclone->NumberFormat->NumberDecimalDigits );
}
/*
This code produces the following output.
DTFI/NFI PROPERTY ORIGINAL MODIFIED CLONE
DTFI.AMDesignator AM a.m.
DTFI.DateSeparator / -
NFI.CurrencySymbol $ USD
NFI.NumberDecimalDigits 2 4
*/
using System;
using System.Globalization;
public class SamplesCultureInfo {
public static void Main() {
// Creates and initializes a CultureInfo.
CultureInfo myCI = new CultureInfo("en-US", false);
// Clones myCI and modifies the DTFI and NFI instances associated with the clone.
CultureInfo myCIclone = (CultureInfo) myCI.Clone();
myCIclone.DateTimeFormat.AMDesignator = "a.m.";
myCIclone.DateTimeFormat.DateSeparator = "-";
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.
Console.WriteLine( "DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE" );
Console.WriteLine( "DTFI.AMDesignator\t{0}\t\t{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator );
Console.WriteLine( "DTFI.DateSeparator\t{0}\t\t{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator );
Console.WriteLine( "NFI.CurrencySymbol\t{0}\t\t{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol );
Console.WriteLine( "NFI.NumberDecimalDigits\t{0}\t\t{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits );
}
}
/*
This code produces the following output.
DTFI/NFI PROPERTY ORIGINAL MODIFIED CLONE
DTFI.AMDesignator AM a.m.
DTFI.DateSeparator / -
NFI.CurrencySymbol $ USD
NFI.NumberDecimalDigits 2 4
*/
Imports System.Globalization
Public Class SamplesCultureInfo
Public Shared Sub Main()
' Creates and initializes a CultureInfo.
Dim myCI As New CultureInfo("en-US", False)
' 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.DateTimeFormat.DateSeparator = "-"
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.
Console.WriteLine("DTFI/NFI PROPERTY" + ControlChars.Tab + "ORIGINAL" + ControlChars.Tab + "MODIFIED CLONE")
Console.WriteLine("DTFI.AMDesignator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator)
Console.WriteLine("DTFI.DateSeparator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator)
Console.WriteLine("NFI.CurrencySymbol" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol)
Console.WriteLine("NFI.NumberDecimalDigits" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits)
End Sub
End Class
' This code produces the following output.
'
' DTFI/NFI PROPERTY ORIGINAL MODIFIED CLONE
' DTFI.AMDesignator AM a.m.
' DTFI.DateSeparator / -
' NFI.CurrencySymbol $ USD
' NFI.NumberDecimalDigits 2 4
複製は、元 CultureInfo のが読み取り専用であっても書き込み可能です。 そのため、複製のプロパティは変更できます。
オブジェクトの簡易コピーは、オブジェクトのコピーにすぎません。 オブジェクトに他のオブジェクトへの参照が含まれている場合、シャローコピーは参照されるオブジェクトのコピーを作成しません。 代わりに、元のオブジェクトを参照します。 これに対し、オブジェクトの詳細コピーでは、オブジェクトのコピーと、そのオブジェクトによって直接または間接的に参照されるすべてのもののコピーが作成されます。
メソッドは Clone 、拡張シャロー コピーを作成します。 、および Calendar の各プロパティによってNumberFormatDateTimeFormatTextInfo返されるオブジェクトもコピーされます。 その結果、複製されたオブジェクトは CultureInfo 、元 CultureInfo のオブジェクトに影響を与えることなく、コピーしたプロパティを変更できます。
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。