C# ArrayList中的克隆方法Clone示例
public class MyArrayList { public static void Main() { //Creates a new ArrayList. ArrayList myArray = new ArrayList(); myArray.Add("one"); myArray.Add("two"); myArray.Add("three"); myArray.Add("four"); myArray.Add("five"); myArray.Add("six"); myArray.Add("seven"); myArray.Add("eight"); myArray.Add("nine"); myArray.Add("ten"); //Displays the values of the ArrayList. Console.WriteLine("The ArrayList contains the following values:"); foreach (string s in myArray) { Console.WriteLine(s); } Console.WriteLine("The shallow copy of arraylist is as:"); myArray.Clone(); foreach (string s in myArray) { Console.WriteLine(s); } } }
在本文中,我将讨论ArrayList的Clone克隆方法。
C# ArrayList的Clone克隆方法创建了ArrayList的浅副本,这就是说此克隆方法只需创建ArrayList的所有元素的副本。
日期:2020-04-11 22:50:16 来源:oir作者:oir