请查看Linqpad中的以下代码,并告诉我为什么它返回0项而不是1项.
void Main()
{
string[] strArray = {"apple", "banana", "cherry", "e"};
List<string> lst = strArray.ToList();
//count all occurences of variable alphabet "e" in LINQ
//tip is to get the occurences of letter "e" in each word
// and then total them together
var lst2 = lst.TakeWhile(c=>c.Equals("banana")).Select(c=>c);
Console.WriteLine(lst2);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码没有像我期望的那样在linqpad中返回1个项目.相反,它返回0项.带有1个项目"banana"的列表应该返回.为什么不呢?