开发者

Why do they name the EventArgs parameter 'e'?

As all of us know, .NET has very good documentation and variable/parameter naming. Oftentimes, you can figure out how to pass parameters to a function just by variable names shown at design time without consulting the documentation at all. Something that is very interesting for me is that the only variable that has an unrelated name is e which is used in nearly all event function declarations such as:

private void button1_Click(object sender, EventArgs e)

private void button1_DragDrop(object sender, DragEventArgs e)

My question is why do they nam开发者_Python百科e all event arguments e? Is there history behind it?


Ah! It was some lazy Microsoft Programmer :). Lolz jokes apart, this is an actual event naming guideline of Microsoft.

http://msdn.microsoft.com/en-us/library/h0eyck3s

This is what the third bullet says.

"Specify two parameters named sender and e. The sender parameter represents the object that raised the event. The sender parameter is always of type object, even if it is possible to use a more specific type. The state associated with the event is encapsulated in an instance of an event class named e. Use an appropriate and specific event class for the e parameter type."


e is short for event, just like args is short for arguments, and i is short for index.


I guess that e is short for event.

Or as someone else once said.. e stands for extra stuff!


e = event

It's unusual at first, but the human brain has a so good ability to adapt to almost anything, that I think it's not a real problem to call them e. Maybe evt or event are more descriptive, but you have to type more characters again and again.

For instance the Euler number is also called "e" instead of "Euler's number" to simplify things, spare a time waste of mathematicians' life. It's not too descriptive, but people got used to it without a problem and it's only one character, so I think e for event is fair enough.


It really should be given a more descriptive name, but its so widely used, accepted, and easily understood it has just stuck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜