Monday, 9 September 2013

List's ForEach() method not acting as expected

List's ForEach() method not acting as expected

Why is this not working?
List<int> test = new List<int>();
for (int i = 0; i < 20; ++i)
test.Add(i);
test.ForEach(t => t = ++t);
The elements in test are not incremented.

No comments:

Post a Comment