0
0
C Sharp (C#)programming~10 mins

Lambda expression syntax in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a lambda that adds two integers.

C Sharp (C#)
Func<int, int, int> add = (x, y) => x [1] y;
Drag options to blanks, or click blank then click option'
A+
B/
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of +
Using * or / which changes the operation
2fill in blank
medium

Complete the code to declare a lambda that checks if a number is even.

C Sharp (C#)
Func<int, bool> isEven = n => n [1] 2 == 0;
Drag options to blanks, or click blank then click option'
A+
B%
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of %
Using * which multiplies instead of checking remainder
3fill in blank
hard

Fix the error in the lambda that returns the square of a number.

C Sharp (C#)
Func<int, int> square = x => x [1] 2;
Drag options to blanks, or click blank then click option'
A*
B**
C^
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using ** which is invalid in C#
Using ^ which is bitwise XOR, not power
4fill in blank
hard

Fill the blank to create a lambda that filters numbers greater than 10.

C Sharp (C#)
Func<int, bool> isGreaterThanTen = n => n [1] 10;
Drag options to blanks, or click blank then click option'
A==
B<
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >
Using != which checks inequality
5fill in blank
hard

Fill all three blanks to create a lambda that returns a dictionary of words and their lengths for words longer than 3 characters.

C Sharp (C#)
var lengths = words.Where(w => w.Length [1] 3).ToDictionary([2] => [3].ToLower(), [2] => [2].Length);
Drag options to blanks, or click blank then click option'
A>
Bword
Cw
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the filter
Using inconsistent variable names in the lambdas