我想从长度小于或等于5的列表中选择所有单词。我当前的代码只返回:
我希望结果是真实的单词。
static void Main()
{
string[] words = { "hello", "Welcome", "Rolling", "in", "The", "Deep" };
var shortWords = from word in words select word.Length <= 5;
foreach (var word in shortWords) {
Console.WriteLine(word);
}
Console.Read();
}
答案 0 :(得分:8)
看起来你打算做
var shortWords = from word in words where word.Length <= 5 select word;
或只是
var shortWords = words.Where(word => word.Length <= 5);