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

Func delegate type 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 Func delegate that takes two integers and returns an integer.

C Sharp (C#)
Func<int, int, [1]> add = (x, y) => x + y;
Drag options to blanks, or click blank then click option'
Aint
Bvoid
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type in Func (Func must return a value).
Using string or bool as return type when adding integers.
2fill in blank
medium

Complete the code to declare a Func delegate that takes a string and returns its length.

C Sharp (C#)
Func<string, [1]> getLength = s => s.Length;
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cbool
Ddouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using string as return type instead of int.
Using bool or double which do not match Length property type.
3fill in blank
hard

Fix the error in the Func delegate declaration to correctly return a boolean indicating if a number is even.

C Sharp (C#)
Func<int, [1]> isEven = n => n % 2 == 0;
Drag options to blanks, or click blank then click option'
Astring
Bbool
Cint
Dvoid
Attempts:
3 left
💡 Hint
Common Mistakes
Using int as return type when the lambda returns a boolean.
Using void which is invalid for Func delegates.
4fill in blank
hard

Fill both blanks to declare a Func delegate that takes a double and an int, and returns a double result.

C Sharp (C#)
Func<[1], [2], double> multiply = (a, b) => a * b;
Drag options to blanks, or click blank then click option'
Adouble
Bint
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping input types or using string/bool as input types.
Using int as first input when it should be double.
5fill in blank
hard

Fill all three blanks to declare a Func delegate that takes two strings and returns a boolean indicating if they are equal.

C Sharp (C#)
Func<[1], [2], [3]> areEqual = (s1, s2) => s1 == s2;
Drag options to blanks, or click blank then click option'
Astring
Bint
Cbool
Ddouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or double as input types instead of string.
Using int or string as return type instead of bool.