C# Enumerable Any(IEnumerable)
Description
Enumerable Any (IEnumerable)
Determines
whether a sequence contains any elements.
Syntax
public static bool Any<TSource>(
this IEnumerable<TSource> source
)
Parameters
TSource
- The type of the elements of source.source
- The IEnumerableto check for emptiness.
Returns
returns true if the source sequence contains any elements; otherwise, false.
Example
The following code example demonstrates how to use Any to determine whether a sequence contains any elements.
/* www . j av a 2s .c o m*/
using System;
using System.Linq;
using System.Collections.Generic;
public class MainClass{
public static void Main(String[] argv){
List<int> numbers = new List<int> { 1, 2 };
bool hasElements = numbers.Any();
Console.WriteLine(hasElements);
}
}
The code above generates the following result.