Convert
Converts all elements in an enumerable list from the its to a destination type by calling a provided conversion function
Source
public IEnumerable<TDestination> Convert<TSource, TDestination>(this IEnumerable<TSource> source, Func<TSource, TDestination> conversionFunc)
{
foreach (TSource element in source)
{
yield return (conversionFunc(element));
}
}
Example
List<string> s = ...;
IEnumerable<int> = s.Convert(s => Convert.ToInt32(x));
Author: Ricardo Peres
Submitted on: 30 jan. 2012
Language: C#
Type: System.Collections.Generic.IEnumerable<T>
Views: 4964