public void Poke() { AngerLevel++; if (AngerLevel >= 3) { Shout?.Invoke(this, EventArgs.Empty); } }
// method public void poke() { AngerLevel++; if (AngerLevel >= 3) { // if something is listening... Shout?.Invoke(this, EventArgs.Empty); } }
//method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { // if something is listening, then call the delegate Shout?.Invoke(this, EventArgs.Empty); } }
// method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { // if somebody listens us... //... then event raises Shout?.Invoke(this, EventArgs.Empty); } }
// method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { // if something is listening... // ...then raise the event //?.Invoke check if the event is not null Shout?.Invoke(this, EventArgs.Empty); } }
public void Poked() { AngerLevel++; if (AngerLevel >= 3) { // if(Shout != null){ // Shout(this,EventArgs.Empty); // } Shout?.Invoke(this, EventArgs.Empty); } }
//method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { //if something is listening.. // if (Shout != null) // { //...then call the delegate // Shout(this, EventArgs.Empty); // } //Below one-liner replaces the above 6 lines. Checking whether an object is null before calling one of its methods is very common. C# 6.0 and later allows the inline null check below. Shout?.Invoke(this, EventArgs.Empty); } }
// method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { // if something is listening /*if (Shout != null) * { * // ...then raise the event * Shout(this, EventArgs.Empty); * }*/ Shout?.Invoke(this, EventArgs.Empty); } }
//method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { // if something is listening // then call the delegate Shout?.Invoke(this, EventArgs.Empty); // if (Shout != null) // { // Shout(this, EventArgs.Empty); // } } }
//method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { //if something is listening Shout?.Invoke(this, EventArgs.Empty); // Same as //if (Shout != null) //{ // // then raise the event // Shout(this, EventArgs.Empty); //} } }
// method public void Poke() { AngerLevel++; if (AngerLevel >= 3) { // if something is listening... /* * if (Shout != null) * { * // ...then call the delegate * Shout(this, EventArgs.Empty); * } */ Shout?.Invoke(this, EventArgs.Empty); } }