HOTSPOT
You have the following code:
For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Hot Area:
HOTSPOT
You have the following code:
For each of the following statements, select Yes if the statement is true. Otherwise, select No.
Hot Area:
yes
yes
no
Agree with you
yes
no https://stackoverflow.com/questions/374398/are-event-subscribers-called-in-order-of-subscription
no
Indeed: Y, N, N:
Also note that the constuctor is executed twice, by new and explicit.
Output will be something like:
First
Second
Third
Third
First
Second
Third
Third,
Wow.. the Main method is located within the Subscriber class.
Is that intended?
Yes YES NO, Tested in VS, it follows an ordering, i cant subscribe first and second person gets his response before me
it was in your case but you can’t “always” rely on it
https://msdn.microsoft.com/en-us/library/mt299485(v=nav.90).aspx
“There can be multiple subscribers to the same event from various locations in the application code. When an event is raised, the subscriber functions are run one at a time in random order.”
YES YES NO
public class Alert
{
public event EventHandler SendMessage;
public void Execute()
{
SendMessage(this, new EventArgs());
}
}
public class Subscriber
{
Alert alert = new Alert();
public void Subscribe()
{
alert.SendMessage += (sender, e) => { Console.WriteLine(“First”); };
alert.SendMessage += (sender, e) => { Console.WriteLine(“Second”); };
alert.SendMessage += (sender, e) => { Console.WriteLine(“Third”); };
alert.SendMessage += (sender, e) => { Console.WriteLine(“Third”); };
}
public void Execute()
{
alert.Execute();
}
public static void Main()
{
Subscriber subscriber = new Subscriber();
subscriber.Subscribe();
subscriber.Execute();
Console.ReadKey();
}
}
Yes Yes No
Out pot is
—————-
First
Second
Third
Third