public static class ListMap
{
public static List Map(List list, Func mapFunction)
{
if (list == null)
{
throw new ArgumentNullException("list");
}
if (mapFunction == null)
{
throw new ArgumentNullException("mapFunction");
}
List outputList = new List();
list.ForEach(t => outputList.Add(mapFunction(t)));
return outputList;
}
}
Usage:
List stringList = new List(new string[] { "1", "2", "3" });
List result = ListMap.Map(stringList, x => int.Parse(x));
This results in a List