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" 

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

posted @ 2011-02-12 18:12  spring yang  阅读(466)  评论(4编辑  收藏  举报