1.Suppose the MovedEventHandler delegate is defined by the statement delegate void MovedEventHandler(). Which of the following correctly...
Question:
1.Suppose the MovedEventHandler delegate is defined by the statement delegate void MovedEventHandler(). Which of the following correctly declares the Moved event?
a.public MovedEventHandler MovedEvent;
b.public event MovedEventHandler MovedEvent;
c.public event Action MovedEvent;
d.Both b and c are correct.
2.Suppose the Employee class is derived from the Person class and the Person class defines an AddressChanged event. Which of the following should you not do to allow an Employee object to raise this event?
a.Create an OnAddressChanged method in the Person class that raises the event.
b.Create an OnAddressChanged method in the Employee class that raises the event.
c.Make the Employee class call OnAddressChanged as needed.
d.Make the code in the Person class that used to raise the event call the OnAddressChanged method instead.
3.Which of the following statements subscribes the myButton_Click event handler to catch the myButton control's Click event?
a.myButton.Click += myButton_Click;
b.myButton_Click += myButton.Click;
c.myButton_Click handles myButton.Click;
d.myButton.Click = myButton_Click;
4.Suppose the Car class provides a Stopped event that takes as parameters sender and StoppedArgs objects. Suppose also that the code has already created an appropriate StoppedArgs object named args. Then which of the following code snippets correctly raises the event?
a.if (!Stopped.IsEmpty) Stopped(this, args);
b.if (Stopped) Stopped(this, args);
c.if (Stopped != null) Stopped(this, args);
d.raise Stopped(this, args);
5.Which of the following statements about events is false?
a.If an object subscribes to an event twice, its event handler executes twice when the event is raised.
b.If an object subscribes to an event twice and then unsubscribes once, its event handler executes once when the event is raised.
c.If an object subscribes to an event once and then unsubscribes twice, its event handler throws an exception when the event is raised.
d.In a Windows Forms application, you can use the Properties window to subscribe and unsubscribe events, and to create empty event handlers.
6.Which of the following statements about inheritance and events is false?
a.A derived class can raise a base class event by using code similar to the following:
if (base.EventName != null) base.EventName(this, args);
b.A derived class cannot raise an event defined in an ancestor class.
c.A class can define an OnEventName method that raises an event to allow derived classes to raise that event.
d.A derived class inherits the definition of the base class's events, so a program can subscribe to a derived object's event.
7.Which of the following statements about exception handling is true?
a.You can nest a try-catch-finally block inside a try, catch, or finally section.
b.A try-catch-finally block must include at least one catch section and one finally section.
c.An exception is handled by the catch section that has the most specific matching exception type.
d.The code in a finally section executes if the code finishes without an error or if a catch section handles an exception but not if the code executes a return statement.
8.Which of the following methods can you use to catch integer overflow exceptions?
a.Use a try-catch-finally block.
b.Use a checked block and a try-catch-finally block.
c.Check the Advanced Build Settings dialog's overflow/underflow box, and use a try-catch-finally block.
d.Either b or c.
9.Which of the following returns true if variable result holds the value float.PositiveInfinity?
a.result == float.PositiveInfinity
b.float.IsInfinity(result)
c.float.IsPositiveInfinity(result)
d.All of the above.
10.Which of the following statements about throwing exceptions is false?
a.If you catch an exception and throw a new one to add more information, you should include the original exception in the new one's InnerException property.
b.If you rethrow the exception ex with the statement throw, the exception's call stack is reset to start at the current line of code.
c.If you rethrow the exception ex with the statement throw ex, the exception's call stack is reset to start at the current line of code.
d.Before a method throws an exception, it should clean up as much as possible, so the calling code has to deal with the fewest possible side effects.
11.Which of the following should you not do when building a custom exception class?
a.Derive it from the System.Exception class, and end its name with Exception.
b.Give it event handlers with parameters that match those defined by the System.Exception class.
c.Make it implement IDisposable.
d.Give it the Serializable attribute.
Step by Step Answer: