,
[ Pobierz całość w formacie PDF ]
.c.A statement lambda must use braces, { }.d.If a statement lambda returns a value, it must use a return statement.256 CHAPTER 6 WORKING WITH DELEGATES, EVENTS, AND EXCEPTIONSX'11.Suppose the MovedEventHandler delegate is defined by the statement delegate voidMovedEventHandler().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.12.Suppose the Employee class is derived from the Person class and the Person class definesan AddressChanged event.Which of the following should you not do to allow an Employeeobject 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 theOnAddressChanged method instead.13.Which of the following statements subscribes the myButton_Click event handler to catch themyButton 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;14.Suppose the Car class provides a Stopped event that takes as parameters senderand StoppedArgs objects.Suppose also that the code has already created an appropriateStoppedArgs object named args.Then which of the following code snippets correctlyraises 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);15.Which of the following statements about events is false?a.If an object subscribes to an event twice, its event handler executes twice when theevent is raised.b.If an object subscribes to an event twice and then unsubscribes once, its event handlerexecutes once when the event is raised.c.If an object subscribes to an event once and then unsubscribes twice, its event handlerthrows an exception when the event is raised.d.In a Windows Forms application, you can use the Properties window to subscribeand unsubscribe events, and to create empty event handlers.Chapter Test Questions 257X'16.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 derivedclasses to raise that event.d.A derived class inherits the definition of the base class s events, so a program cansubscribe to a derived object s event.17.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 onefinally section.c.An exception is handled by the catch section that has the most specific matchingexception type.d.The code in a finally section executes if the code finishes without an error or if acatch section handles an exception but not if the code executes a return statement.18.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 atry-catch-finally block.d.Either b or c.19.Which of the following returns true if variable result holds the valuefloat.PositiveInfinity?a.result == float.PositiveInfinityb.float.IsInfinity(result)c.float.IsPositiveInfinity(result)d.All of the above.20.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 shouldinclude 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 stackis reset to start at the current line of code.c.If you rethrow the exception ex with the statement throw ex, the exception s callstack 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 thecalling code has to deal with the fewest possible side effects.258 CHAPTER 6 WORKING WITH DELEGATES, EVENTS, AND EXCEPTIONSX'21.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 theSystem.Exception class.c.Make it implement IDisposable.d.Give it the Serializable attribute [ Pobierz całość w formacie PDF ] |
Archiwum
|