
Untitled
By: a guest on
Jun 21st, 2012 | syntax:
None | size: 0.50 KB | hits: 13 | expires: Never
How to get an empty list of a collection?
var result = MyCollection.Take(0).ToList();
var result = MyCollection.Where(p => false).ToList();
public static IList<T> CreateEmptyCopy(this IEnumerable<T> source)
{
return source.Take(0).ToList();
}
var result = MyCollection.CreateEmptyCopy();
public static IList<T> GetEmptyList<T>(this IEnumerable<T> source)
{
return new List<T>();
}
var emp = MyCollection.GetEmptyList();
Enumerable.Empty<T>();
Enumerable.Empty<T>().ToList<T>();