为什么这会返回零结果?

Jon*_*Jon 1 .net c# linq generics c#-4.0

我有一个List<List<string>>,当我尝试搜索List<string>它时,它返回没有结果.

有任何想法吗?

谢谢

        List<List<string>> test = new List<List<string>>();

        List<string> ff = new List<string>();
        ff.Add("1");
        ff.Add("ABC 1");
        test.Add(ff);

        ff = new List<string>();
        ff.Add("2");
        ff.Add("ABC 2");

        test.Add(ff);

        var result = test.Where(x=>x.Contains("ABC"));

        //result.Count(); is 0
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 13

您的列表中都没有包含"ABC"元素.

如果要查找包含"ABC"元素作为子字符串的列表,可以执行以下操作:

var result = test.Where(x => x.Any(y => y.Contains("ABC")));
Run Code Online (Sandbox Code Playgroud)