3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RiderでLINQのメソッドチェインの途中結果を確認する

Last updated at Posted at 2025-04-13

C#のLINQメソッドチェインで思った通りの結果にならない時、途中結果を確認できたら便利ですよね。

この投稿では、RiderでLINQのメソッドチェインの途中結果を確認する方法を紹介します。

  • この投稿のスクリーンショットは、Rider 2025.1 RC1のものです
  • この投稿では、次の様なコードを使って説明します
var persons = new List<Person>
{
    new ("田中太郎", 35),
    new ("鈴木花子", 28),
    new ("佐藤一郎", 42),
    new ("山田梅子", 29),
    new ("田中二郎", 32)
};

var names = persons
    .Where(p => p.Age > 30)
    .Select(p => p.Name)
    .Order();

foreach (var name in names)
{
    Console.WriteLine(name);
}

record struct Person(string Name, int Age);

LINQの処理をする前の行でブレークポイントを貼り、デバッグ実行し、LINQの処理をステップオーバーします。

スクリーンショット 2025-04-12 14.42.18.png

するとDebug Windowの「Thread & Variables」タブに、LINQのメソッドチェインごとの結果が表示されます。次のスクリーンショットは、該当の「Thread & Variables」タブを拡大した様子です。

スクリーンショット 2025-04-12 14.34.28.png

Exploreボタンをおし、Results要素を開くと、各要素を確認することができます。(スクリーンショット中に、「Expanding will force enumaration of the object」と注意があることに気をつけてください。)

スクリーンショット 2025-04-12 14.33.31.png


この様にRiderでは、LINQのメソッドチェインの途中結果を確認できます。


Rider 2025.1以降を使うのであれば、「Debug LINQ expressions」が便利です。

(Rider 2025.1 RCの段階では、Top-level statementsで使えないかもしれません。)

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?