本文介绍了你如何串连在C#名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有:

List<string> myList1;
List<string> myList2;
int placeToCheckValues = 0; //Used for breakpoints since the values don't get updated until after the line is executed

myList1 = getMeAList();
placeToCheckValues = 0;    //Checked myList1 here, it contains 4 strings

myList2 = getMeAnotherList();
placeToCheckValues = 0;    //Checked myList2 here, it contains 6 strings

myList1.Concat(myList2);
placeToCheckValues = 0;    //Checked mylist1 again, it contains 4 strings... why?

我跑在Visual Studio 2008和每个执行后,设置断点与此类似code。后 myList1 = getMeAList(); myList1 包含四个字符串,我pressed的加号按钮,使确保他们不都是空值。

I ran code similar to this in Visual Studio 2008 and set break points after each execution. After myList1 = getMeAList();, myList1 contains four strings, and I pressed the plus button to make sure they weren't all nulls.

myList2 = getMeAnotherList(); myList2 包含六弦,我检查,以确保他们间没有T空...后 myList1.Concat(myList2); myList1只包含四根弦。这是为什么?

After myList2 = getMeAnotherList();, myList2 contains six strings, and I checked to make sure they weren't null... After myList1.Concat(myList2); myList1 contained only four strings. Why is that?

推荐答案

的毗连返回一个新序列的。尝试 myList1.AddRange(myList2)

Concat returns a new sequence without modifying the original list. Try myList1.AddRange(myList2).

这篇关于你如何串连在C#名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 03:04