Ch13 Complete Test Bank Delegates, Anonymous Methods, And - Test Bank | Visual C# 5e by Tony Gaddis. DOCX document preview.

Ch13 Complete Test Bank Delegates, Anonymous Methods, And

Starting Out with Visual C#, 5e (Tony Gaddis)

Chapter 13 Delegates, Anonymous Methods, and Lambda Expressions

TRUE/FALSE

1. When a delegate refers to a method, you can use the delegate to call the method.

2. A delegate type describes the method that the delegate can refer to.

3. Once a delegate has been created it can never be assigned to another method.

4. Because a delegate refers to a method, it cannot be passed as an argument to a method.

5. A delegate can only reference one method.

6. A method that has no name is known as an anonymous method.

7. A lambda expression is a shortcut technique for writing an anonymous method.

8. If a delegate type specifies no parameters, you cannot use a lambda expression with that delegate because lambda expressions must have one parameter.

9. If a delegate type specifies a void return type any lambda expression used with that delegate will also be void.

10. To use more than one parameter in a lambda expression, you write a comma-separated list and enclose the list in parentheses.

11. If a delegate type specifies multiple parameters, you cannot use a lambda expression with that delegate because lambda expressions can only have one parameter.

12. The compiler can determine the data type of a lambda expression's parameter from the delegate type declaration.

13. The body of a lambda expression can only contain a single statement.

14. The .NET framework provides all the delegate types you will ever need.

15. The .NET built-in Action delegate type invokes a method that accepts one argument and returns a boolean value.

16. A Predicate delegate invokes a method that accepts 0 to 16 arguments and returns a boolean value.

17. The .NET built-in Func delegate type invokes a method that accepts 0 to 16 arguments and returns a value.

18. If you want to pass arguments to an Action delegate, you must specify the data type of each of the delegate's parameters.

19. There are no List methods that will work with delegates.

20. In the following code, the name of the delegate is trip.

Func<int, double> Triple = delegate(int trip)

{

return trip * 3;

};

MULTIPLE CHOICE

1. An object that works like a reference variable that refers to a method is known as a __________.

a.

predicate

b.

lambda

c.

delegate

d.

subroutine

2. You can use a delegate to reference a(n) __________.

a.

object

b.

variable

c.

method

d.

structure

3. To create and use a delegate you must __________.

a.

declare a delegate type

b.

create an instance of the delegate type

c.

make the instance of the delegate type reference a method

d.

You must do all of these things.

4. A delegate can reference __________.

a.

any method or object

b.

only a method with a return type

c.

any method with a parameter list that matches that of the delegate type.

d.

only a method that has a return type and a parameter list that matches that of the delegate type.

5. 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;

a.

delegate void Welcome(string str);

b.

private void DisplayMessage(string greeting)

c.

MessageBox.Show(greeting);

d.

Welcome Hello = DisplayMessage;

6. 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;

a.

delegate void Welcome(string str);

b.

private void DisplayMessage(string greeting)

c.

MessageBox.Show(greeting);

d.

Welcome Hello = DisplayMessage;

7. When a delegate is __________ another method, the method's return type and parameter list must match that of the delegate type.

a.

reassigned to

b.

referred to

c.

passed to

d.

joined to

8. A delegate that references multiple methods is known as a(n) __________ delegate.

a.

predicate

b.

action

c.

multicast

d.

multitype

9. To add a method to a delegate, you can use the __________.

a.

+ operator

c.

Add function

b.

+= operator

d.

Plus function

10. A shortcut technique for writing an anonymous method is known as a(n) __________.

a.

lambda delegate

c.

anon method

b.

lambda expression

d.

predicate

11. A method that has no name is __________.

a.

not allowed in C#

c.

the same as a delegate

b.

known as an anonymous method

d.

All of these are true.

12. Which of the following is the lambda operator?

a.

=>

b.

+=

c.

>=

d.

=+

13. 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);

a.

Expon Cube = num => num * num * num;

b.

int Cube = num => num * num * num;

c.

Expon Cube => num * num * num;

d.

Expon int Cube => num = num * num * num;

14. 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);

a.

MultiCalc Product = (int x * int y * int z);

b.

MultiCalc Product => (int x * int y * int z);

c.

MultiCalc Product => x * y * z;

d.

MultiCalc Product = (x, y, z) => x * y * z;

15. It is possible to write multiple statements in the body of a lambda expression so long as the __________.

a.

last statement is a return statement

b.

statements do not return a value

c.

statements are enclosed in curly braces

d.

delegate type is void

16. Which of the following built-in delegate types invokes a void method that accepts 0 to 16 arguments?

a.

Action

b.

Func

c.

Predicate

d.

multicast

17. Which of the following built-in delegate types invokes a method that accepts one argument and returns a boolean value?

a.

Action

b.

Func

c.

Predicate

d.

multicast

18. 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.");

a.

student

b.

IsOdd

c.

Predicate

d.

x

19. 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.");

a.

true

c.

1

b.

false

d.

The number is not even.

20. Which of the following List methods will not accept delegates as arguments?

a.

Exists

b.

ForEach

c.

RemoveAll

d.

All of these accept delegates as arguments

Document Information

Document Type:
DOCX
Chapter Number:
13
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 13 Delegates, Anonymous Methods, And Lambda Expressions
Author:
Tony Gaddis

Connected Book

Test Bank | Visual C# 5e

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party