You are developing an application that includes a class named BookTracker for tracking library books. The
application includes the following code segment. (Line numbers are included for reference only.)
01 public delegate void AddBookCallback(int i);
02 public class BookTracker
03 {
04 List<Book> books = new List<Book>();
05 public void AddBook(string name, AddBookCallback callback)
06 {
07 books.Add(new Book(name));
08 callback(books.Count);
09 }10 }
11
12 public class Runner
13 {
14
15 BookTracker tracker = new BookTracker();
16 public void Add(string name)
17 {
18
19 }
20 }
You need to add a book to the BookTracker instance. What should you do?
A.
Insert the following code segment at line 14:
private static void PrintBookCount(int i)
{
…
}
Insert the following code segment at line 18:
AddBookCallback callback PrintBookCount;
B.
Insert the following code segment at line 18:
tracker.AddBook(name, delegate(int i)
{
…
});
C.
Insert the following code segment at line 11:
delegate void AddBookDelegate(BookTracker bookTracker);
Insert the following code segment at line 18:
AddBookDelegate addDelegate = (bookTracker) =>
{
…
}
addDelegate(tracker);
D.
Insert the following code segment at line 11:
delegate void AddBookDelegate(string name, AddBoookCallback callback);
Insert the following code segment at line 18:
AddBookDelegate adder = (i, callback) =>
{
…
};