C# C:linq返回布尔值而不是字符串
我想从长度小于或等于5的列表中选择所有单词。我的当前代码仅返回以下内容: 符合事实的 错误的 错误的 符合事实的 符合事实的 符合事实的 我希望结果是真实的单词C# C:linq返回布尔值而不是字符串,c#,linq,C#,Linq,我想从长度小于或等于5的列表中选择所有单词。我的当前代码仅返回以下内容: 符合事实的 错误的 错误的 符合事实的 符合事实的 符合事实的 我希望结果是真实的单词 static void Main() { string[] words = { "hello", "Welcome", "Rolling", "in", "The", "Deep" }; var shortWords = from word in words select word.Length <= 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();
}
看来你是有意的
var shortWords = from word in words where word.Length <= 5 select word;
或者只是
var shortWords = words.Where(word => word.Length <= 5);
如果这对你有帮助的话,值得将其作为答案,这样人们就不会犹豫回答你未来的问题。