【发布时间】:2010-11-05 17:55:25
【问题描述】:
如果我有:
List<string> myList1;
List<string> myList2;
myList1 = getMeAList();
// Checked myList1, it contains 4 strings
myList2 = getMeAnotherList();
// Checked myList2, it contains 6 strings
myList1.Concat(myList2);
// Checked mylist1, it contains 4 strings... why?
我在 Visual Studio 2008 中运行了与此类似的代码,并在每次执行后设置断点。在myList1 = getMeAList(); 之后,myList1 包含四个字符串,我按下加号按钮以确保它们不都是空值。
在myList2 = getMeAnotherList(); 之后,myList2 包含六个字符串,我检查以确保它们不为空......在myList1.Concat(myList2); myList1 之后只包含四个字符串。这是为什么呢?
【问题讨论】:
标签: c# arrays list concatenation