Answers for "c# initialize event"

C#
0

c# initialize event

//I absolutely don't remember where i found this, but it works just fine
public event System.Action myEvent = delegate {};
//It seems that an event mainly just takes on the type of a delegate array
void Example()
{
	//Because lack of proof, it's safer to use the method below
	myEvent?.Invoke();
  	//^^Use the null-conditional operator '?' to safely call/invoke the event even if it is null due to having zero subscribers
}
Posted by: Guest on March-02-2022

C# Answers by Framework

Browse Popular Code Answers by Language