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的更多相关文章
随机推荐
- mybatis系列-10-一对一查询
10.1 需求 查询订单信息,关联查询创建订单的用户信息 10.2 resultType 10.2.1 sql语句 确定查询的主表:订单表 确定查询的关联表:用户表 关联查询 ...
- Linux中MySQL5.5解压版普通用户安装
#查看本机mysql 安装路径 [hadoop@SY-0134 toolkit]$ rpm -qa|grep -i mysql [hadoop@SY-0134 toolkit]$ whereis my ...
- CDH5.5.1版HBase安装使用LZO压缩
1.安装 RHEL/CentOS/Oracle 5 Navigate to this link and save the file in the /etc/yum.repos.d/ dire ...
- 关于 终端 ls 命令 不能区分文件和目录的问题
默认的,使用ls命令来显示目录内容的时候,“终端”对于目录.可执行文件等特殊类型的文件并没有使用颜色来显示,只有使用“ls -G”时,才能显示颜色,这可真是不方便.有没有方法可以默认显示颜色呢?方法当 ...
- delphi debug release区别是什么?
1. 基础知识介绍: Debug编译:是为了便于程序调试,所以目标代码里附加有许多额外的东西.Release编译:是产品可作为正式拷贝发布了,已经不需要那些仅为调试而编译进去东西. (在 Releas ...
- codeforces 630A Again Twenty Five!
A. Again Twenty Five! time limit per test 0.5 seconds memory limit per test 64 megabytes input stand ...
- POJ1328Radar Installation(贪心)
对于每一个点,可以找到他在x轴上的可行区域,这样的话就变为了对区间的贪心. #include<iostream> #include<stdio.h> #include<s ...
- react-native 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
Q: A:
- 【Java】JDBC编程套路
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/5847020.html 学习Java开发,一个必须掌握的知识点,就是数据库操作.当程序需要用到的数据达到一定程度 ...
- WinForm中的DataGridView控件显示数据字典方案2
winform代码分析object数据库 做这部分功能的时候,上网搜索了很多资料,发现很少涉及到这方面的解决方案,找了相关的问题帖子,很多人都叫使用视图去处理,当然,用视图是可以解决这个问题,但是,这 ...