Use SelectMany with ? operator in CSharp

Description

The following code shows how to use SelectMany with ? operator.

Example


//w ww . j a v  a 2s . co  m
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        string[] presidents = {"A", "Art", "Buch", "Bush", "Carter", "land"};

        IEnumerable<char> chars = presidents
         .SelectMany((p, i) => i < 5 ? p.ToArray() : new char[] { });

        foreach (char ch in chars)
            Console.WriteLine(ch);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ