Why do event handlers always have a return type of void?

前端 未结 11 2131
夕颜
夕颜 2020-12-05 23:30

Hey, I wondered why is it that the return type of events such as

private void button1_Click(object sender, EventArgs e)

is always void?

11条回答
  •  既然无缘
    2020-12-06 00:02

    Aside from the fact that .NET expects a certain signature for the events in standard controls, consider this: an event can have multiple event handlers attached, which one of the return values would be used?

    It just doesn't make sense for event handlers to return a value. Typically, they will modify the state of some object that derives from EventArgs to communicate something back to whatever fired the event.

提交回复
热议问题