public void OnSomethingHappened() { Console.WriteLine("SOS!"); SomethingHappened?.Invoke(); SendMessage?.Invoke(this.GetType(), new MessageArgs() { ShipName = "Titanic", Message = "SOS" }); }
private void timer1_Tick(object sender, EventArgs e) { TimeSpan ts = qurrentQuiz.End.Subtract(DateTime.Now); TimeLeft = ts.ToString("s''"); SomethingHappened?.Invoke(this, EventArgs.Empty); if (TimeLeft.Equals("0")) { getResult(); } }
public EventsMulticast() { SomethingHappened += Method1; SomethingHappened += Method2; SomethingHappened += Method3; SomethingHappened += Method4; SomethingHappened += Method5; SomethingHappened.Invoke(new object(), null); //On encounter of exception at Method3, Method4 and Method5 are not called }
public override void Pay() { if (Money >= trip.Price) { Money -= trip.Price; SomethingHappened += Client_SomethingHappened; SomethingHappened?.Invoke(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{Name},you dont't have enough money"); Console.ResetColor(); } }
public override void Pay() { if (Account >= ride.Price) { Account -= ride.Price; SomethingHappened += AccountState; SomethingHappened?.Invoke(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{Name},sorry, but you dont't have enough money"); Console.ResetColor(); } }
public void Demo(Person person) { // Simplest use. string name = person?.Name; // Can be chained. The first null will break the chain. string zipCode = person?.Address.ZipCode ?? ""; // Works nicely with the null-coalescing operator. string zipCode2 = person?.Address?.ZipCode ?? "00000"; // An example with a nullable type. Person.Age is an int. int?age1 = person?.Age; int age2 = (person?.Age).GetValueOrDefault(); // Works with invoking methods. Here Level is an enum. Level level = (person?.GetLevel()).GetValueOrDefault(Level.Unknown); // Great to guard when an event has no subscribers. SomethingHappened?.Invoke(this, new SomethingHappenedEventArg()); }
public void DoSomething() => SomethingHappened?.Invoke(this, EventArgs.Empty);
private void InvokeSomethingHappened() { SomethingHappened?.Invoke(); }
public void Trigger(string something) { SomethingHappened?.Invoke(this, new SomethingHappenedEventArgs(something)); }
public void OnSomethingHappened() { SomethingHappened?.Invoke(this, EventArgs.Empty); }
private void SimulateSomethingHappened() { SomethingHappened?.Invoke(this, new EventArgs()); }
/// <summary> /// Raise event. /// </summary> internal void FireEvent() { Console.WriteLine("Fire SomethingHappened!!!"); SomethingHappened?.Invoke(); }