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" 

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

  • 相关阅读:
    JSP中的内容布局
    IDEA tomcat三步实现热部署
    十分钟git-服务器搭建ssh登陆
    postgres 备份数据库
    Hadoop集群部署-Hadoop 运行集群后Live Nodes显示0
    Hadoop集群部署
    DP:Miking Time(POJ 3616)
    DP:Islands and Bridges(POJ 2288)
    DP:Apple Catching(POJ 2385)
    DP:Skiing(POJ 1088)
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1952757.html
Copyright © 2011-2022 走看看