删除List <string []>中的对象

时间:2016-01-18 17:00:34

标签: c# winforms

我有以下列表:

List<string[]> filmlist = new List<string[]>();

列表包含像

这样的数组
string[] row = { "0", "1", "2", "3", "4", "5", "6", Convert.ToString(filmcounter) };

我想删除此列表中具有特定值 filmcounter 的项目。

谢谢!

2 个答案:

答案 0 :(得分:0)

如果您的附加评论澄清了,您想要删除包含特定电影计数器的整行,您可以做一些不同的事情。

所以使用这个示例数据:

    timeout - a timeout in milliseconds, after which the action will return with an error

Specifies the amount of time that Selenium will wait for actions to complete.

Actions that require waiting include "open" and the "waitFor*" actions.
The default timeout is 30 seconds.

删除包含指定filmcounter值的所有行:

List<string[]> filmlist = new List<string[]>()
{
    new[] { "0", "1", "2", "3", "4", "5", "6" },
    new[] { "0", "1", "2", "3", "4", "5", "6" },
    new[] { "0", "1", "2", "3", "4", "5", "7" },
};
string filmcounter = "6";

仅删除包含特定filmcounter值的第一行:

filmlist.RemoveAll(x => x.Contains(filmcounter));

第二个示例中的FindIndex将返回包含filmcounter值的第一个索引。然后我们可以使用此索引删除该行。如果没有匹配,它将返回-1。

答案 1 :(得分:-3)

foreach(String value in filmlist){
    filmlist.Remove(value);
}

检查C#方法删除(),它是你想要的。