簡體   English   中英

C#:linq返回boolean而不是string

[英]C#: linq return boolean instead of string

我想從長度小於或等於5的列表中選擇所有單詞。我當前的代碼只返回:

  1. 真正
  2. 真正
  3. 真正
  4. 真正

我希望結果是實際的單詞。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM