[英]How to use LINQ to return the result as Dictionary<string,string> in C#
[英]C#: linq return boolean instead of string
我想從長度小於或等於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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.