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

Predicate 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 Predicate delegate that checks if a number is positive.

C Sharp (C#)
Predicate<int> isPositive = [1];
Drag options to blanks, or click blank then click option'
Ax => x > 0
Bx => x == 0
Cx => x < 0
Dx => x != 0
Attempts:
3 left
💡 Hint
Common Mistakes
Using a lambda that checks for zero or negative numbers instead of positive.
Not returning a boolean value.
2fill in blank
medium

Complete the code to use the Predicate delegate to find if any number in the array is even.

C Sharp (C#)
int[] numbers = {1, 3, 5, 6};
bool hasEven = Array.Exists(numbers, [1]);
Drag options to blanks, or click blank then click option'
Ax => x % 2 == 1
Bx => x % 2 == 0
Cx => x > 5
Dx => x < 0
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for odd numbers instead of even.
Using conditions unrelated to evenness.
3fill in blank
hard

Fix the error in the Predicate delegate that checks if a string is empty.

C Sharp (C#)
Predicate<string> isEmpty = s => s.[1] == 0;
Drag options to blanks, or click blank then click option'
AIsEmpty
BEquals
CEmpty
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method IsEmpty.
Trying to call Length as a method instead of a property.
4fill in blank
hard

Fill both blanks to create a Predicate that checks if a number is between 10 and 20 (inclusive).

C Sharp (C#)
Predicate<int> isBetween = x => x [1] 10 && x [2] 20;
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators like < or > only.
Mixing up the order of operators.
5fill in blank
hard

Fill all three blanks to create a Predicate that checks if a string starts with 'A' and has length greater than 3.

C Sharp (C#)
Predicate<string> check = s => s.[1]("A") && s.[2] [3] 3;
Drag options to blanks, or click blank then click option'
AStartsWith
BLength
C>
DContains
Attempts:
3 left
💡 Hint
Common Mistakes
Using Contains instead of StartsWith.
Using incorrect comparison operators for length.