【发布时间】:2014-06-18 11:52:48
【问题描述】:
public static List<List<string>> Threads = new List<List<string>>();
...
public static void CheckIfResponseContainWords()
{
foreach (var thread in Threads) {
thread.RemoveAll(line => line == "" ||
!WordsList.words.Any(w => line.Contains(w)));
}
}
在Threads 在这种情况下,我有 50 个列表。在 List 中有不同数量的索引。
在我遍历CheckIfResponseContainWords 中的线程列表之后,一些列表是空的。
现在我想再次循环Threads 中的所有列表并删除所有空列表。
列出要删除的 count = 0。
在检查单词是否不存在之后,CheckIfResponseContainWords 方法中是否也有一种方法可以做到这一点?
但想法是,在我完成 CheckIfResponseContainWords 之后,从 Threads 中删除空列表。
我该怎么做?
编辑
public static void CheckIfResponseContainWords()
{
// Here first to remove from all the Lists in Threads fir index ( index 0 ).
foreach (var thread in Threads) {
thread.RemoveAll(line => line == "" ||
!WordsList.words.Any(w => line.Contains(w)));
}
}
编辑
另一个小问题。
public static void CheckIfResponseContainWords()
{
foreach (var thread in Threads)
{
if (thread.Count > 0)
thread.RemoveAt(0);
thread.RemoveAll(line => line == "" ||
!WordsList.words.Any(w => line.Contains(w)));
}
Threads.RemoveAll(list => list.Count == 0);
}
在此之前:
if (thread.Count > 0)
thread.RemoveAt(0);
我想删除它并首先这样做:
thread.RemoveAll(line => line == "" ||
!WordsList.words.Any(w => line.Contains(w)));
但是,如果任何 List 的索引 0 中不存在来自 words 的单词,则删除整个 List。 如果仅在索引 0 的线程中的任何列表中存在一个或多个单词,则保留和删除整个列表索引的单词。
它应该看起来像这样:
公共静态无效 CheckIfResponseContainWords() { foreach(线程中的 var 线程) {
// Check here every List in Threads index 0 if any word from words exist in it only in index 0. If it does then continue to the thread.RemoveAll(line.....and remove all words from the List.
但是,如果在线程索引 0 中的任何列表中不存在任何单词,则删除整个列表并移至下一个,不要创建线程。RemoveAll(line.... 只需删除列表。在对所有列出那些离开的删除每个 List index0: if (thread.Count > 0) thread.RemoveAt(0);
thread.RemoveAll(line => line == "" ||
!WordsList.words.Any(w => line.Contains(w)));
}
Threads.RemoveAll(list => list.Count == 0);
}
如果 List 中存在一个或多个单词,则检查 Threads 中任何 List 中的索引 0 移动一位,并在此 List 中检查所有不存在单词的单词的索引,删除它们。
如果在索引 0 中不存在任何单词,则删除整个列表并且不要将行部分。
我首先需要确定在任何列表的索引 0 处是否存在一个或多个单词,如果还没有删除整个列表,则继续并继续下一个。
【问题讨论】: