引用类型赋值的时候老赋值引用,大侠们都是怎么深度拷贝的?
解决方案 »
- 触发了GridView1_SelectedIndexChanged动作后,分页不起作用了?
- 利用partial class将一个类写在两个文件里有什么好处
- 帮帮忙!急在线等
- C#SOCKET编程 TCP协议求代码学习
- 盼高手解惑!关于多种语言的调用:C#和java之间的调用,除了ws难道只能用c++通过jni编译dll?
- 请问如何返回上一题(ASP.NET+C#)
- 关于二级用户不能登录的问题
- 初学C#,来送分!50分,请问定时器如何用!
- 在一个大循环中,如何让系统获得消息?
- 有不有有关c#的新闻组(中文)?你们上哪个新闻组??
- datalist中table去边框线样式问题
- 关于扫雷问题,请做过相关游戏的朋友来指教指教
实现ICloneable接口估计成吧,麻烦.
不过需要注意的是不能Mark[NonSerialized] attribute,否则反序列化回来会挂。实现ICloneable接口是最好的。
{
private string name;
private int age; // Copy constructor.
public Person(Person previousPerson)
{
name = previousPerson.name;
age = previousPerson.age;
} //// Alternate copy contructor calls the instance constructor.
//public Person(Person previousPerson)
// : this(previousPerson.name, previousPerson.age)
//{
//} // Instance constructor.
public Person(string name, int age)
{
this.name = name;
this.age = age;
} // Get accessor.
public string Details
{
get
{
return name + " is " + age.ToString();
}
}
}class TestPerson
{
static void Main()
{
// Create a new person object.
Person person1 = new Person("George", 40); // Create another new object, copying person1.
Person person2 = new Person(person1);
Console.WriteLine(person2.Details); // Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
// Output: George is 40