C# List> 赋值问题
各位高手看以下代码
List<string> myCode = new List<string>();
myCode.Add("0");
myCode.Add("1");
myCode.Add("2");
myCode.Add("3");
myCode.Add("4");
myCode.Add("5");
myCode.Add("6");
myCode.Add("7");
myCode.Add("8");
myCode.Add("9");
List<List<string>> lastList=new List<List<string>>();
List<string> item = new List<string>();
item.Add("a");
item.Add("b");
item.Add("c");
item.Add("d");
item.Add("e");
item.Add("f");
item.Add("g");
item.Add("h");
item.Add("i");
for (int i = 0; i < 10; i++)
{
lastList.Add(item);
}
for (int j = 0; j < 10; j++)
{
lastList[j][0] = myCode[j];
}
本来lastList输出的值应是这样lastList[0][0]=0...lastList[2][0]=2...
但是现在全部变成最后一个值lastList[0][0]=9...lastList[1][0]=9.....lastList[2][0]=9
请各位高手看看问题出在哪.先谢过了