Ch13CardLib time of execution event handler
I am studying the code of the CardLib that raises the LastCardDrawn event (page 380 in the book) and I have the following question about the code:
Why can you assume that the line: "return cards[cardNum]" is executed BEFORE the method that subscribed to the LastCardDrawn event (in this case the Reshuffle() method). Is it possible that the Reshuffle method is called BEFORE the return statement (maybe only if there would be a lot more code to process in the GetCard method after raising the event "holding up" the return statement) and so the card returned by the GetCard method is the last card of the shuffled deck instead of the last card of the original deck?
Isn't it safer to first store the last card in a local variable, then raise the event (triggering the Reshuffle() method) and then return the local variable containing the last card?
|