什么才算好样式的事件定义:
What is considered better style for an event definition:
public event Action<object, double> OnNumberChanged;
或
public delegate void DNumberChanged(object sender, double number);
public event DNumberChanged OnNumberChanged;
第一时间不打字,但委托人给名称的参数。当我键入此,我觉得2号是赢家,但我可能是错的。
The first takes less typing, but the delegate one gives names to the parameters. As I type this, I think number 2 is the winner, but I could be wrong.
编辑:不同的(第三个)的做法是赢家。阅读下文。
A different (third) approach is the winner. Read below.
无论是1或2。第三个选项是赢家
Neither 1 or 2. A third option is the winner
public event EventHandler<NumberChangedEventArgs> NumberChanged;
你打破了一些风格指南开发在C#中,如使用类型事件参数不扩展EventArgs的。
You're breaking a number of style guidelines for developing in C#, such as using a type for event args that doesn't extend EventArgs.
是的,你能做到这样,因为编译器不关心。然而,人们阅读你的code会做跆拳道。
Yes, you can do it this way, as the compiler doesn't care. However, people reading your code will do a WTF.