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
- Author: Dawid van Zyl
- Submitted on: 11/4/2009 2:46:21 PM
- Language: C#
- Type: System.Collections.Generic.IEnumerable<T>
- Views: 6802
Double click on the code to select all.