简单介绍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#代码convert.tochar(null);出现异常的详解(图)

C#获取listview鼠标下的item案例

.net的优点

C#_调用封装的一个类实现导出excel表格的功能

详解C#执行存储过程并将结果填充到gridview的示例代码

C#和c ++的区别是什么

详细介绍C#中out和ref的区别(图文)

C#实现关闭子窗口和关闭父窗口的案例

C#用来做什么的

简单介绍C#类的继承的示例代码

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




打赏

取消

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

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

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

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

评论

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