为什么他们将 EventArgs 参数命名为“e”?
众所周知,.NET 拥有非常好的文档和变量/参数命名。通常,您只需通过设计时显示的变量名称就可以弄清楚如何将参数传递给函数,而无需查阅文档。对我来说非常有趣的是,唯一具有不相关名称的变量是 e
,它几乎在所有事件函数声明中使用,例如:
private void button1_Click(object sender, EventArgs e )
private void button1_DragDrop(object sender, DragEventArgs e)
我的问题是为什么他们将所有事件参数命名为 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 name all event arguments e
? Is there history behind it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
啊!这是一些懒惰的微软程序员:)。 Lolz 开玩笑说,这是微软真实的事件命名指南。
http://msdn.microsoft.com/en-us/library/h0eyck3s
这就是第三个子弹所说的。
“指定名为 sender 和 e 的两个参数。sender 参数表示引发事件的对象。sender 参数始终为 object 类型,即使可以使用更具体的类型。与事件关联的状态封装在名为 e 的事件类的实例 对 e 参数类型使用适当且特定的事件类。”
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 是 event 的缩写,就像 args 是 argument 的缩写,i 是 index 的缩写一样。
e is short for event, just like args is short for arguments, and i is short for index.
我猜
e
是 event 的缩写。或者正如其他人曾经说过的那样..
e
代表额外的东西!I guess that
e
is short for event.Or as someone else once said..
e
stands for extra stuff!e = 事件
起初这很不寻常,但人脑具有非常好的适应几乎任何事物的能力,因此我认为将它们称为 e 并不是一个真正的问题。也许 evt 或 event 更具描述性,但您必须一次又一次地输入更多字符。
例如,欧拉数也被称为“e”而不是“欧拉数”,以简化事物,避免浪费数学家的时间。它不是太具有描述性,但人们毫无问题地习惯了它,而且它只有一个字符,所以我认为 e 表示事件是足够公平的。
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.