我想使用一组字符搜索字符串列表,并希望找到匹配项而不考虑顺序。例如,如果我的列表包含
List<string> testList = new List<string>() { "can", "rock", "bird" };
我希望能够使用“irb”进行搜索并让它返回 bird。我必须多次这样做,所以我正在寻找最有效的方法。
最佳答案
var query = "irb";
List<string> testList = new List<string>() { "can", "rock", "bird" };
var result = testList.Where(i => query.All(q => i.Contains(q)));
对testList
中的每一项进行测试,看是否包含query
中的所有字母
关于c# - 包含无顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42289385/