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" 

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

  • 相关阅读:
    windos下安装多个mysql服务
    mysql 提示too many connections”的解决办法
    python打包成exe
    对于点击后需要等待一段时间才会有的元素的操作
    python自动化报错
    自动化测试中对不能输入的框体的处理
    对于下拉框的处理方法
    selenium自动化遇见Cannot find class in classpath问题
    企业如何留住人才
    如何成为一名优秀的前端工程师
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1952757.html
Copyright © 2011-2022 走看看