zoukankan      html  css  js  c++  java
  • list 泛型时出现的一个Bug

    新建一个类

     public class FolderBE
        {
           public string FolderOne
           { get; set; }
           public string FolderTwo
           { get; set; }
           public string FolderThree
           { get; set; }
           public string FolderFour
           { get; set; }
           public string FolderFive
           { get; set; }
        }

    然后:

                         List<FolderBE> listFolder = new List<FolderBE>();

                        FolderBE folder = new FolderBE();
                        folder.FolderOne = "one";
                        folder.FolderTwo = "two";
                        folder.FolderThree = "three";

                        listFolder.Add(folder);

                        folder.FolderFour = "four";

      然后listFolder里的一条数据的FolderFour也会变成"four";

       所以我们在使用它时要这样:

                         List<FolderBE> listFolder = new List<FolderBE>();

                        FolderBE folder = new FolderBE();
                        folder.FolderOne = "one";
                        folder.FolderTwo = "two";
                        folder.FolderThree = "three";

                        listFolder.Add(folder);

                      folder = new FolderBE();
                        folder.FolderOne = "one";
                        folder.FolderTwo = "two";
                        folder.FolderThree = "three";

                        folder.FolderFour = "four";

    listFolder里面的数据 FolderFour不会变成"four" 

    最近发现,如果有误,请告诉我.    

  • 相关阅读:
    STL--sort源码分析
    进程和线程的区别
    static 关键字 静态成员变量及静态成员函数
    二叉树遍历总结 先序、中序、后续、广度、深度
    C++用new和不用new创建类对象区别
    传输层--TCP和UDP的区别
    传输层的作用
    微信商户/H5支付申请 被拒原因:网站存在不实内容或不安全信息
    Oracle本地网络服务名配置
    存储过程常用技巧
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1952757.html
Copyright © 2011-2022 走看看