我有一個數據視圖,它由使用字符串列表的對象填充。我想通過在文本框中輸入搜索詞來選擇合適的條目。如何過濾使用字符串列表的字符串列表的列表
我的對象:
class my_object
{
List<string> column1 = new List<string>();
List<string> column2 = new List<string>();
List<string> column3 = new List<string>();
List<string> column4 = new List<string>();
}
我的條目數據視圖:
List<my_object> entries = new List<my_object>();
我的目的是過濾像在Windows資源管理器但不同的搜索功能中的條目,我想包括四列而不僅僅是具有文件名的列。 有沒有可能做到這一點?
我曾嘗試:
internal static List<my_object> SearchObject(this List<my_object> Source, List<string> SearchWords)
{
List<my_object> results = new List<my_object>();
foreach (my_object m in Source)
{
foreach(string s in SearchWords)
{
// Filter Column 1
foreach(string c1 in m.column1)
{
if(c1.IndexOf(s) != -1)
{
results.Add(m);
break;
}
}
}
}
return results;
// Problem:
// This function only filters the first column.
// If I want to filter the next column, I have to break all 'foreach' blocks
// except the '(my_object m in Source)' block...
// It the 'break' would work for more the one loop, this method would work...
}
希望你能幫助我。
感謝您的快速回答。 –
不幸的是,這種解決方案只適用於整個單詞... –