C#_deepCopy
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows; namespace ConsoleApplication1
{
[Serializable]
class Person
{ public Person()
{ }
public int age { set; get; }
public string name { set; get; } }
class Program
{
public static Person deepCopy(Person value)
{
using (MemoryStream stream = new MemoryStream())
{
BinaryFormatter formattor = new BinaryFormatter();
formattor.Serialize(stream,value);
stream.Flush();
stream.Seek(,SeekOrigin.Begin);
return (Person)formattor.Deserialize(stream);
}
}
static void Main(string[] args)
{ Person p1 = new Person();
p1.age=;
p1.name = "aaa"; Person p2 = new Person();
p2.age = ;
p2.name = "aaa";
//Console.WriteLine(p1==p2);
//Console.WriteLine(p1.Equals(p2)); Person p3 = deepCopy(p2);
p2.age = ;
Console.WriteLine(p2.age);
Console.WriteLine(p3.age);
Console.ReadKey(); }
}
}
C#_deepCopy的更多相关文章
随机推荐
- MVC中的ActionResult
ActionResult是控制器方法执行后返回的结果类型,控制器方法可以返回一个直接或间接从ActionResult抽象类继承的类型,如果返回的是非ActionResult类型,控制器将会将结果转换为 ...
- File-nodejs
文件系统模块是一个简单包装的标准 POSIX 文件 I/O 操作方法集.您可以通过调用require('fs')来获取该模块.文件系统模块中的所有方法均有异步和同步版本. 文件系统模块中的异步方法需要 ...
- [Hive - LanguageManual] Archiving for File Count Reduction
Archiving for File Count Reduction Note: Archiving should be considered an advanced command due to t ...
- 自动化运维工具ansible-如何设置客户端多python版本问题
问题:在使用ansible进行管理客户主机时,发现客户主机安装了多个版本的python,并且默认版本为3.0 shell>>cat list 192.168.2.9 shell>&g ...
- UVA 10054 The Necklace(欧拉回路,打印路径)
题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 转载IEnumerable与IEnumerator区别
public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { ...
- UVA 11354 Bond(MST + LCA)
n<=50000, m<=100000的无向图,对于Q<=50000个询问,每次求q->p的瓶颈路. 其实求瓶颈路数组maxcost[u][v]有用邻接矩阵prim的方法.但是 ...
- HDU 1828 Picture (线段树+扫描线)(周长并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y ...
- 10款无需编程的App DIY开发工具
10款无需编程的App DIY开发工具 你有一个很棒的创意但不会编程怎么办?外包.合伙开发还是从零学编程?这里提供另外一种方式--使用无需编程的App DIY开发工具.DIY开发工具不仅节省了开发时 ...
- GCD求最大公约数
求最大公约数哪个强,果断GCD,非递归版本和递归版本如下: #include<iostream> using namespace std; int gcd(int a, int b){ / ...