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的更多相关文章

随机推荐

  1. ASP.NET常用技巧方法代码断

    1. 打开新的窗口并传送参数:传送参数:response.write("<script>window.open('*.aspx?id="+this.DropDownLi ...

  2. 【windows核心编程】一个HOOK的例子

    一.应用场景 封装一个OCX控件,该控件的作用是来播放一个视频文件,需要在一个进程中放置四个控件实例. 由于控件是提供给别人用的,因此需要考虑很多东西. 二.考虑因素 1.控件的父窗口resize时需 ...

  3. iOS多线程之GCD小记

    iOS多线程之GCD小记 iOS多线程方案简介 从各种资料中了解到,iOS中目前有4套多线程的方案,分别是下列4中: 1.Pthreads 这是一套可以在很多操作系统上通用的多线程API,是基于C语言 ...

  4. Trail: JDBC(TM) Database Access(2)

    package com.oracle.tutorial.jdbc; import java.sql.CallableStatement; import java.sql.Connection; imp ...

  5. HDU ACM Eight

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 解题背景: 看到八数码问题,没有任何的想法,偶然在翻看以前做的题的时候发现解决过类似的一道题,不 ...

  6. 如何使用git创建远程仓库(供局域网多人使用)

    用git init(默认创建的是私人的仓库)创建的仓库,推送是不会成功的. 因此在git server端,我们要用 git --bare init --shared=group 来创建一个bare库, ...

  7. HDU 2275 multiset

    题意:n个操作 Push 入容器 Pop弹出一个 满足<=该数的最大的数(若没有输出No Element!) 开始用set打了一遍wrong了,这里入容器的数是有重复的,所以用multiset ...

  8. 图文讲解:iOS App提交流程

    原文:http://www.toceansoft.com/ios/3287.jhtml 一.证书的导出 1.1.前期工作 首先你需要有一个苹果的开发者帐号,一个Mac系统. 如果没有帐号可以在打开ht ...

  9. java读取properties的工具类PropertiesUtil

    package org.properties.util; import java.io.FileInputStream; import java.io.FileOutputStream; import ...

  10. How Much Work Does it Take to be a Successful Mathematician?

    http://mathoverflow.net/questions/9799/how-much-work-does-it-take-to-be-a-successful-mathematician# ...