ToCollection<T>()
Convert a IEnumerable<T> to a Collection<T>
Source
public static class Extension
{
#region Public Static Methods
public static Collection<T> ToCollection<T>(this IEnumerable<T> enumerable)
{
var collection = new Collection<T>();
foreach (T i in enumerable)
collection.Add(i);
return collection;
}
#endregion Public Static Methods
}
Example
var somearray = new int[] {1,2,3,4,5,6,7,8}
Collection<int> numbers = (from item in somearray
where item > 4
select item).ToCollection();
Author: Dawid van Zyl
Submitted on: 4 nov. 2009
Language: C#
Type: System.Collections.Generic.IEnumerable<T>
Views: 12556