简体   繁体   English

在Visual Studio 2015中添加EventHandler不会像2010年那样自动完成

[英]Adding an EventHandler in Visual Studio 2015 does not auto complete like it did in 2010

I'm trying to migrate to Visual Studio 2015 from 2010 and finding the EventHandler declarations a bit different. 我正在尝试从2010迁移到Visual Studio 2015,并发现EventHandler声明有些不同。

In 2010 I could type the following... 在2010年,我可以输入以下内容...

this.MyNewEvent += (space)

and it would pop up with "press tab to auto complete". 然后会弹出“按Tab键自动完成”。 Then after pressing tab I would get the following... 然后按Tab后,我将得到以下内容...

this.MyNewEvent += new EventHandler<MyNewEventArgs>(MyClassName_MyNewEvent);

void MyClassName_MyNewEvent(object sender, MyNewEventArgs e)
{
    throw new NotImplementedException();
}

Now in 2015, when I type the following... 现在是2015年,当我输入以下内容时...

this.MyNewEvent += (space)

I get the following... 我得到以下...

this.MyNewEvent += MyClassName_MyNewEvent;

private void MyClassName_MyNewEvent(object sender, MyNewEventArgs e)
{
    throw new NotImplementedException();
}

It's weird if that's the new way to do it because a lot of my old code has it the way it presented it in 2010. 如果那是新的方法,那是很奇怪的,因为我的许多旧代码都采用了2010年提出的方法。

Why is the new EventHandler<>() format not used any longer? 为什么不再使用new EventHandler<>()格式? Is there a way to change it back to the way 2010 did it? 有没有办法将其改回2010年的方式?

I waited for DIEGO to claim the credit but it seems that's not going to happen. 我等着DIEGO要求归功,但看来这不会发生。 :) :)

As stated in the question's comments, the two different formats render the same exact results. 如问题评论中所述,两种不同的格式呈现相同的准确结果。 There is no reason to change the way they are used but it only makes sense to use the c#2.0 format as it requires less characters, is much friendlier looking, and takes the redundancy out of the definitions. 没有理由更改它们的使用方式,但是仅使用c#2.0格式才有意义,因为它需要较少的字符,外观友好得多,并且从定义中删除了冗余。

The article How to: Subscribe to and Unsubscribe from Events (C# Programming Guide) shows how they are the same just presented differently with different frameworks/IDEs. 如何:订阅和取消订阅事件》(《 C#编程指南》)一文显示了如何使用不同的框架/ IDE以不同的方式呈现它们。

c#1.0 c#1.0

this.MyNewEvent += new EventHandler<MyNewEventArgs>(MyClassName_MyNewEvent);
void MyClassName_MyNewEvent(object sender, MyNewEventArgs e)
{
    throw new NotImplementedException();
}

c#2.0 C#2.0

this.MyNewEvent += MyClassName_MyNewEvent;
private void MyClassName_MyNewEvent(object sender, MyNewEventArgs e)
{
    throw new NotImplementedException();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM