C# Enumerable Empty

Description

Returns an empty IEnumerable that has the specified type argument.

Syntax


public static IEnumerable<TResult> Empty<TResult>()

Parameters

  • TResult - The type to assign to the type parameter of the returned generic IEnumerable .

Returns

Returns an empty IEnumerable that has the specified type argument.

Example

The following code example demonstrates a possible application of the Empty() method.


/*from  w  w  w.j  ava 2 s  .  c om*/
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
    
    string[] names1 = { "A" };
    string[] names2 = { "B", "C","D", "Java" };
    string[] names3 = { "XML", "C#","VB","HTML", "Javascript" };

    List<string[]> namesList = new List<string[]> { names1, names2, names3 };
    IEnumerable<string> allNames =namesList.Aggregate(Enumerable.Empty<string>(),
                                      (current, next) => next.Length > 3 ? current.Union(next) : current);

    foreach (string name in allNames)
    {
        Console.WriteLine(name);
    }
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Linq »




Enumerable