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" 

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

  • 相关阅读:
    洛谷P1527 矩阵乘法——二维树状数组+整体二分
    bzoj1503 [NOI2004]郁闷的出纳员——splay
    bzoj4811 [Ynoi2017]由乃的OJ 树链剖分+位运算
    D Dandan's lunch
    C Sleepy Kaguya
    B bearBaby loves sleeping
    A AFei Loves Magic
    II play with GG
    angular的路由和监听路由的变化和用户超时的监听
    ng-disabled 指令
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1952757.html
Copyright © 2011-2022 走看看