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的更多相关文章
随机推荐
- 在Lua里写unity游戏笔记
gameobject.GetComponent<Transform>(); 翻译成Lua: gameObject:GetComponent (luanet.ctype (Transform ...
- 记:Tmall活动页面开发
一.年轻的我 “无人不成商”,如果一个电子商务网站想要做起来,搞活动时必不可少的(引入流量.提高用户黏度.活跃网站氛围),今天打折,明天送红包. (立秋活动,右) 作为一个前端,我当然要从技术的角度来 ...
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing ...
- [Hive - LanguageManual] Alter Table/Partition/Column
Alter Table/Partition/Column Alter Table Rename Table Alter Table Properties Alter Table Comment Add ...
- hadoop多次格式化后,导致datanode启动不了,怎么办?(伪分布式)
根据当初 hadoop 安装目录下 conf 目录的 core-site.xml 的设置,找到该目录: 进入该目录 在 data 和 name 文件夹下均有 current 文件夹 ,和 cur ...
- 引擎 innodb 与 myisam 的区别
使用innodb引擎 , 查询800万数据的统计: 将innodb 引擎 改成 MyISAM引擎: alter table test_count engine = MyISAM;
- 最大二位子数组和问题(homework-02)
前面已经谈过最大一维子数组和问题,这里面扩展到二维. 一. 常规情况 一个矩形的数组,找到一个矩形的子数组有最大的元素和,求这个和. 1. 从朴素算法入手,枚举矩形数组的4个顶点,以此计算其数组和.同 ...
- Hadoop port to Jxta P2P Framework
https://www.java.net/forum/topic/jxta/jxta-community-forum/hadoop-port-jxta-p2p-framework —————————— ...
- 利用管道实现Shell多进程
shell中有个&,表示该程序在后台执行,其实是fork了一个子进程,跟系统调用是一样的. 在实际的操作过程中,有时需要控制后台程序的个数,毕竟启动太多的后台,会对服务的性能造成影响. 所以需 ...
- Linux下的JDK安装rpm命令详解
1. 安装程序 #rpm -ivh jdk-7u79-linux-x64.rpm 出现安装协议等,按接受即可. 2.设置环境变量. #vi /etc/profile JAVA_HOME=/usr/ja ...