Enumerable.DefaultIfEmpty : Enumerable « System.Linq « C# / C Sharp by API






Enumerable.DefaultIfEmpty

 

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MainClass {
    public static void Main() {
        string[] presidents = {"G", "H", "a", "H", "over", "Jack"};

        string name =
          presidents.Where(n => n.Equals("H")).DefaultIfEmpty("Missing").First(); Console.WriteLine(name);

    }
}

   
  








Related examples in the same category

1.Enumerable.Aggregate
2.Enumerable.Average()
3.Enumerable.Cast
4.Enumerable.Count()
5.Enumerable.Distinct()
6.Enumerable.ElementAt
7.Enumerable.ElementAtOrDefault
8.Enumerable.ElementsAfterSelf
9.Enumerable.Empty
10.Enumerable.First
11.Enumerable.OrderBy
12.Enumerable.Range
13.Enumerable.Repeat
14.Enumerable.Where