Languages, patterns, technologies, frameworks.
Can you predict the output of the code above without actually running it?
List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
list.FindAll( i => { Console.WriteLine( i ); return i < 5; } );
Documentation states that List(Of T).FindAll "is an O(n) operation, where n is Count", we can guess that the delegate passed as the argument is always called for each item in the list. The output should be:12345678910
For every element from list we will try to evaluate the lambda expression, which will print the value. So Aleksander gave correct answer.Btw. How many puzzles will are you going to throw at us?
Post a Comment
2 comments:
Documentation states that List(Of T).FindAll "is an O(n) operation, where n is Count", we can guess that the delegate passed as the argument is always called for each item in the list. The output should be:
1
2
3
4
5
6
7
8
9
10
For every element from list we will try to evaluate the lambda expression, which will print the value. So Aleksander gave correct answer.
Btw. How many puzzles will are you going to throw at us?
Post a Comment