返回 C# 中的函数
这个片段
private void westButton_click(object sender, EventArgs ea)
{
PlayerCharacter.Go(Direction.West);
}
我为北、南和东重复了
。 如何声明一个函数,让我以编程方式生成 ir 等方法?
例如,我希望能够调用
northButton.Click += GoMethod(Direction.North);
而不是定义方法,然后
northButton.Click += new EventHandler(northButton.Click);
I have this snippet
private void westButton_click(object sender, EventArgs ea)
{
PlayerCharacter.Go(Direction.West);
}
repeated for North, South and East.
How can I declare a function that'd let me generate methods like ir programmatically?
e.g., I'd like to be able to call
northButton.Click += GoMethod(Direction.North);
instead of defining the method, and then
northButton.Click += new EventHandler(northButton.Click);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(或者...)
(or...)
我似乎找到了解决方案:
我唯一关心的是绑定时间; 如果当我调用GoMethod时PlayerCharacter为
null
,会发生什么?I seem to have found a solution:
My only concern would be about binding time; if PlayerCharacter is
null
when I call GoMethod, what would happen?