What is the difference between these possibilities to raise an event in C#? [duplicate]

StackOverflow https://stackoverflow.com/questions/18482308

  •  26-06-2022
  •  | 
  •  

문제

Imagine an event

private event EventHandler SampleEvent;

which should be raised. I know 3 ways to do this, but I don't get the difference between two of them which are

SampleEvent(this, EventArgs.Empty);

and

SampleEvent.Invoke(this, EventArgs.Empty);

What is the difference between those two and what advantages and disadvantages does either method have?

도움이 되었습니까?

해결책

Since event is represented by a delegate internally, Invoke method is present there. Omitting it in calling is just a compiler trick to have a more readable code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top