• 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" 

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

  • 相关阅读:
    CF1324F Maximum White Subtree
    CF1204C Anna, Svyatoslav and Maps
    CF1187E Tree Painting
    CF1304E 1-Trees and Queries
    深入探究jvm之类装载器
    深入探究jvm之GC的算法及种类
    深入探究jvm之GC的参数调优
    spring源码解析之AOP原理
    spring注解扫描组件注册
    cas-client单点登录客户端拦截请求和忽略/排除不需要拦截的请求URL的问题
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1952757.html
Copyright © 2020-2023  润新知