Enumerable.Empty<'TResult> Method ()


Returns an empty IEnumerable<'T> that has the specified type argument.

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)

static member Empty<'TResult> : unit -> IEnumerable<'TResult>

Return Value

Type: System.Collections.Generic.IEnumerable<'TResult>

An empty IEnumerable<'T> whose type argument is TResult.

Type Parameters


The type to assign to the type parameter of the returned generic IEnumerable<'T>.

The Empty<'TResult>() method caches an empty sequence of type TResult. When the object it returns is enumerated, it yields no elements.

In some cases, this method is useful for passing an empty sequence to a user-defined method that takes an IEnumerable<'T>. It can also be used to generate a neutral element for methods such as Union<'TSource>. See the Example section for an example of this use of Empty<'TResult>().

The following code example demonstrates how to use Empty<'TResult>() to generate an empty IEnumerable<'T>.

No code example is currently available or this language may not be supported.

The following code example demonstrates a possible application of the Empty<'TResult>() method. The Aggregate<'TSource> method is applied to a collection of string arrays. The elements of each array in the collection are added to the resulting IEnumerable<'T> only if that array contains four or more elements. Empty<'TResult> is used to generate the seed value for Aggregate<'TSource> because if no array in the collection has four or more elements, only the empty sequence is returned.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top