【发布时间】:2015-06-23 08:21:17
【问题描述】:
我对在 C# 中使用 List 作为数组还是很陌生。所以我在使用时遇到了问题。
我正在尝试使用Remove 从List<int[]> 中删除int[](整数数组),但未能从List<int[]> 中删除int[]。
代码如下:
List<int[]> trash = new List<int[]>()
{
new int[] {0,1},
new int[] {1,0},
new int[] {1,1}
};
int[] t1 = {0,1};
trash.Remove(t1);
这只是一个错误吗?
还是无法识别int[]?
【问题讨论】:
-
它们是不同的对象。您必须按索引或使用相同的参考删除
-
不是错误。您正在尝试删除不在列表中的数组。您的第二次尝试
Console.WriteLine(t1 == trash[0])。它们不一样。 -
哦,非常感谢你们所有人。 :D