public class xcc : ICloneable
{
static IList<string> a = new List<string>();
IList<string> b = new List<string>();
public void test()
{
a.Add("a");
xcc xcc = new xcc();
xcc = ((xcc)Clone());
b = xcc.a;
a.Clear();
foreach (string s in b)
{
Console.Write(s);
}
Console.ReadLine();
}
public object Clone()
{ return this.MemberwiseClone();
}
}请指教。最好有代码,相关教程也行 感谢
{
static IList<string> a = new List<string>();
IList<string> b = new List<string>();
public void test()
{
a.Add("a");
xcc xcc = new xcc();
xcc = ((xcc)Clone());
b = xcc.a;
a.Clear();
foreach (string s in b)
{
Console.Write(s);
}
Console.ReadLine();
}
public object Clone()
{ return this.MemberwiseClone();
}
}请指教。最好有代码,相关教程也行 感谢
{
IList<string> a = new List<string>();
IList<string> b = new List<string>(); public void test()
{
a.Add("a");
xcc xcc1 = ((xcc)Clone());
b = xcc1.a;
a.Clear();
foreach (string s in b)
{
Console.Write(s);
}
Console.ReadLine();
} public object Clone()
{
xcc x = new xcc();
x.a = new List<string>();
x.b = new List<string>();
foreach (var item in a)
{
x.a.Add((string)item.Clone());
}
foreach (var item in b)
{
x.b.Add((string)item.Clone());
}
return x;
}
}
你那个例子根本不是什么深拷贝,关于深拷贝和浅拷贝的知识建议你自己上网去查一下
public class xcc
{
static IList<string> a = new List<string>();
IList<string> b = new List<string>(); public void test()
{
a.Add("a");
foreach (var item in a)
{
b.Add((string)item.Clone());
}
a.Clear();
foreach (string s in b)
{
Console.Write(s);
}
Console.ReadLine();
}
}