LoginSignup
6
11

More than 5 years have passed since last update.

[C#][LINQ] nullを除外する

Posted at

よく使うのに検索にはひっかからなかったので一応メモ

実装方法

Where で null じゃないものを抽出する

リストからnullを除外する
this.HogeList
    .Where(x => x != null);

Null除外専用の構文がないのか探したけども見当たらなかった

使用例

Rxで実装する時に、Subscribe内でifで除外するよりは、Whereで除外したほうが良い気がする
(以下の例はReactivePropertyを使用したものです)

Rxでの利用
this.FileList
    .Where(x => x != null)
    .Where(x => x.Count > 0)
    .Subscribe(x =>
    {
        this.SelectedItem.Value = x[0];
    });
6
11
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
6
11