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

Expression-bodied lambdas 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 create an expression-bodied lambda that adds two numbers.

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 '+' will subtract the numbers.
Using '*' or '/' will multiply or divide instead of adding.
2fill in blank
medium

Complete the code to create an expression-bodied lambda that returns the square of a number.

C Sharp (C#)
Func<int, int> square = x => x [1] x;
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' will add the number to itself, not square it.
Using '-' or '/' will not produce the square.
3fill in blank
hard

Fix the error in the expression-bodied lambda that returns true if a number is even.

C Sharp (C#)
Func<int, bool> isEven = x => x [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 '-' will not check for evenness.
Using '/' will give the quotient, not the remainder.
4fill in blank
hard

Fill both blanks to create an expression-bodied lambda that returns true if a string is longer than 5 characters.

C Sharp (C#)
Func<string, bool> isLong = s => s.[1] > [2];
Drag options to blanks, or click blank then click option'
ALength
B5
CCount
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length for strings.
Comparing to 10 instead of 5.
5fill in blank
hard

Fill all three blanks to create an expression-bodied lambda that returns a dictionary with keys as uppercase strings and values as their lengths.

C Sharp (C#)
var result = [1].ToDictionary([2] => [2].ToUpper(), [3] => [3].Length);
Drag options to blanks, or click blank then click option'
Awords
Bword
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using 'list' instead of the actual collection name.