213 Chapter 13
To add a method to a delegate, you can use the ________. + operator Add function += operator Plus function
+= operator
Which of the following is the lambda operator? += =+ => >=
=>
Which of the following built-in delegate types invokes a void method that accepts 0 to 16 arguments? multicast Predicate Func Action
Action
Which of the following List methods will NOT accept delegates as arguments? ForEach RemoveAll Exists All of these accept delegates as arguments
All of these accept delegates as arguments
A delegate can reference ________. any method with a parameter list that matches that of the delegate type. only a method that has a return type and a parameter list that matches that of the delegate type. any method or object only a method with a return type
Any method with a parameter list that matches that of the delegate type
Given the following delegate type declaration, which statement creates a delegate of the Expon type that references a method that returns the cube of a variable, num? delegate int Expon(int num); Expon int Cube => num = num * num * num; Expon Cube = num => num * num * num; Expon Cube => num * num * num; int Cube = num => num * num * num;
Expon Cube = num => num * num * num;
Given the following code that creates a Predicate delegate and invokes the method, what is the name of the delegate? Predicate<int> IsOdd = student ==> student % 2 == 1; if (IsOdd(x)) MessageBox.Show("The number is not even."); x IsOdd student Predicate
IsOdd
A method that has no name is ________. known as an anonymous method not allowed in C# the same as a delegate All of these are true.
Known as an anonymous method
Given the following delegate type declaration, which statement creates a lambda expression for a delegate named Product? delegate void MultiCalc(int x, int y, int z); MultiCalc Product => x * y * z; MultiCalc Product = (int x * int y * int z); MultiCalc Product = (x, y, z) => x * y * z; MultiCalc Product => (int x * int y * int z);
MultiCalc Product = (x, y, z) => x * y * z;
A delegate that references multiple methods is known as a(n) ________ delegate. multicast multitype predicate action
Multicast
Which of the following built-in delegate types invokes a method that accepts one argument and returns a boolean value? Action Predicate Func multicast
Predicate
Given the following code that creates a Predicate delegate and invokes the method, what would display if x = 23? Predicate<int> IsOdd = student ==> student % 2 == 1; if (IsOdd(x)) MessageBox.Show("The number is not even."); 1 true The number is not even. false
The number is not even
Given the following code, which statement creates an instance of the delegate? delegate void Welcome(string str); private void DisplayMessage(string greeting){ MessageBox.Show(greeting); } Welcome Hello = DisplayMessage; Welcome Hello = DisplayMessage; delegate void Welcome(string str); MessageBox.Show(greeting); private void DisplayMessage(string greeting)
Welcome Hello = DisplayMessage;
To create and use a delegate you must ________. declare a delegate type make the instance of the delegate type reference a method create an instance of the delegate type You must do all of these things.
You must do all of these things
An object that works like a reference variable that refers to a method is known as a ________. lambda subroutine delegate predicate
delegate
Given the following code, which statement creates a delegate type named Welcome? delegate void Welcome(string str); private void DisplayMessage(string greeting){ MessageBox.Show(greeting); } Welcome Hello = DisplayMessage; Welcome Hello = DisplayMessage; delegate void Welcome(string str); private void DisplayMessage(string greeting) MessageBox.Show(greeting);
delegate void Welcome(string str)
A shortcut technique for writing an anonymous method is known as a(n) ________. anon method predicate lambda delegate lambda expression
lamda expression
You can use a delegate to reference a(n) ________. structure object method variable
method
When a delegate is ________ another method, the method's return type and parameter list must match that of the delegate type. joined to reassigned to referred to passed to
reassigned to
It is possible to write multiple statements in the body of a lambda expression so long as the ________. last statement is a return statement statements are enclosed in curly braces delegate type is void statements do not return a value
statements are enclosed in curly braces