简单介绍C#中List<T>对象的深度拷贝问题


当前第2页 返回上一页

测试如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

using System;

using System.Collections.Generic;

using System.Collections ;

using System.Linq;

using System.Text;

using System.IO;

using System.Runtime.Serialization;

using System.Runtime.Serialization.Formatters.Binary;

 

namespace LINQ

{

  [Serializable]

  public class tt

  {

    private string name = "";

 

    public string Name

    {

      get { return name; }

      set { name = value; }

    }

    private string sex = "";

 

    public string Sex

    {

      get { return sex; }

      set { sex = value; }

    }

  }

 

  class LINQTest

  {

    public static T Clone<T>(T RealObject)

    {

      using (Stream objectStream = new MemoryStream())

      {

        IFormatter formatter = new BinaryFormatter();

        formatter.Serialize(objectStream, RealObject);

        objectStream.Seek(0, SeekOrigin.Begin);

        return (T)formatter.Deserialize(objectStream);

      }

    }

 

 

    public static void Main()

    {

      List<tt> lsttt = new List<tt>();

      tt tt1 = new tt();

      tt1.Name = "a1";

      tt1.Sex = "20";

      lsttt.Add(tt1);

      List<tt> l333 = new List<tt>();

      l333.Add(Clone<tt>(lsttt[0]));

      l333[0].Name = "333333333";

   }

 }

}

以上就是简单介绍C#中List<T>对象的深度拷贝问题的详细内容!

返回前面的内容

相关阅读 >>

C#初步体验fastreport 报表(图)

C#教程】C# 枚举(enum)

C#如何计算2个字符串相似度的示例代码分享

C#实现在listview中插入图片的示例代码分享

C#用什么软件编程?

C#教程】C# 数据类型

C#描述数据结构1:统计代码执行时间对象的代码详解

详解介绍C#是如何获取文件md5与sha1

C# 日志记录类创建的源码分享

C#中把image无损转换为icon的实例详解

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...