简体   繁体   中英

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.

In 2010 I could type the following...

this.MyNewEvent += (space)

and it would pop up with "press tab to auto complete". Then after pressing tab I would get the following...

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...

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.

Why is the new EventHandler<>() format not used any longer? Is there a way to change it back to the way 2010 did it?

I waited for DIEGO to claim the credit but it seems that's not going to happen. :)

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.

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#1.0

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

c#2.0

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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