Converts items using specified delegate. Items can be converted to another type.
Using:
1 2 3 4 5 |
var conv = new Converter<int, decimal>(x => (decimal)(x+1)); var listB = listA.ConvertAll<decimal>(conv); |
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { var listA = new List<int>(); listA.Add(100); listA.Add(200); listA.Add(300); listA.Add(400); listA.Add(500); listA.Add(600); listA.Add(700); var conv = new Converter<int, decimal>(x => (decimal)(x + 1)); var listB = listA.ConvertAll<decimal>(conv); Console.ReadLine(); } } |