Join Reynald Adolphe for an in-depth discussion in this video Understanding the improved edit and continue, part of C# 6.0 First Look.
- Now that we've covered the new features of C# 6, I wanted to highlight a few more things on Visual Studio 2015 that I thought were worth mentioning. One of the neatest features I'm excited about is the enhancements in debugging, specifically, editing code as you step through the debugging process. The ability to edit code while debugging in Visual Studio has been around for quite some time, however, it didn't always support many new features that kept being added to C# in newer releases. This Edit Continue feature has been rebuilt to allow much more flexibility.
Let's go ahead and demonstrate how. On line 25, let's put a breakpoint there. To start the debug process, let's click on the green arrow at the top of the screen. What we're going to want to do is step up to line 27. On the right hand side, I want you to notice that we used to have a Comedian class, it's no longer there because I want to demonstrate dynamically creating it during the debug process.
Let's put our cursor right below the Console.WriteLine, hit Enter, and then, let's create a Collection. Specifically, a Collection of comics. We'll make this a generic List of Comedian. Now what I'd like to do is show you that if we click on Comedian and do ctrl + . we'll get the option to generate that class.
We couldn't do that before. This is part of the new feature. Let's go ahead and generate that class by choosing the second option. And here's your class, that just pops up right below you. Now, why don't we go ahead and add to that Collection our first comic. The first thing I want to do is add a Name property, and then the name of the Comedian.
Next, we'll add Age. We'll say 55. After that, let's say FavoriteSeason, I'm guessing would be Spring. Close the curly brace, add a semicolon, let's get rid of this extra curly brace. If we click on Name, and do ctrl + . this will give us the option to generate a property for Name.
If we scroll down, there you go. It brought that up. That's pretty cool. We're still in the debug process here. Let's do the same for age, ctrl + . Let's go ahead and do ctrl + . for Season, and we're going to want to come down here and choose Generate new type... because we're going to want an enum for Season. enum is the default value, and we don't want a new file, let's click OK.
For Spring, ctrl + ., same process, Generate enum member this time, and then, for FavoriteSeason, ctrl + . let's generate that property in our Comedian class. There you go, there's the property, and there's our enum right below. If we actually click on this yellow arrow and drag it up, and step through, we should see that we have our Collection.
We're still in the debug process, and there's our comic. Let's drill down to see Raw View, Non-Static Members, Items, and we see our Comedian. I want to go ahead and add another Comedian to this Collection. This Comedian, his name will be Bob Hope. Age, 76.
His FavoriteSeason is Summer. Let's make sure that we have the right amount curly braces. Get rid of this, and for Summer, let's click on there, do ctrl + . and add that member. There you go. Again, if we come back up, looks like I dragged a little bit too far up.
I'm going to click Restart so that we can continue. If we come back up and step through again, now if we look at our Collection, we have two items. Two Comedians, Richard Pryor and Bob Hope. Now what I'd like to go ahead and demonstrate is our ability to actually query this Collection in real time during the debug process.
Let's go ahead and enter a variable called whoLovesSpring, and say we are getting this from our List of Comedians, comics, where our FavoriteSeason is equal to Spring, then select.
Let's carefully bring that yellow arrow back up to the top, and when we step and hover, let's go to View Results and there you go. It selects the Comedian that we wanted, who also has a FavoriteSeason of Spring, and that's Richard Pryor. That's all pretty great, and that's it. There's one more thing I'd like to show you, and it's regarding the Immediate and Watch window, and that's next.
- Introducing the new IDE in Visual Studio 2015
- Leveraging nameof expressions
- Using index initializers
- Using await in catch and finally blocks
- Using static
- Resolving conflict instance methods