ToCollection<T>()

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();

Description

Convert a IEnumerable<T> to a Collection<T>

Details

Double click on the code to select all.

 

;