edit & continue in C# 2.0 ...
Oooh man i gotta say this is one of the best new features added to C#. it was asked for by the community, it was rumored almost to death during early betas, but thankfully Microsoft once again listened to what it's customers wanted and decided to throw us a little lifeline here with this one.
Yes, yes i know the "purists" out there call it evil and refuse to see the point of it but hear me out ...
Imagine that you are trying to debug a hectic application. whilst you are stepping through your code to see whether everything works as it should you see that you've made a small mistake; a database query is missing a comma between fields. Cursing your torrid luck, you stop the application, make the correction and start all over again.... welcome to the life of a C# 1.0 developer ...
What a pain in the butt! yes i know you should've just done it properly the first time ... but how many of us do that ?!?
Now step in C# 2.0 with edit & continue; now you can simply fix your sql query on the fly and continue onwards without taking the PT (physical torture) of stopping the debugger, editing the code, recompiling your entire project, then painstakingly stepping through everything again to get back to the point where you were 10 minutes ago.
So time for a demo ...
Create a simple Console application in C# 2.0, and do something simple as shown below ...
static void Main(string[] args)
{
string s = "this is sooooo boring!";
Console.WriteLine(s);
}
Set a breakpoint on the Console.WriteLine line and run your app. when the code hits your breakpoint, change the value of s using your autos window,
Now press F11 and go look what happened;
simply wicked!
yes i know this is a trivial example but with Edit and Continue you can do so much more ...
you can change code on the fly;
static void Main(string[] args)
{
string s = "Hello World";
for(int i=0; i
Set a breakpoint on the Console.Write method call and start your debugger ...
this silly code sample has a subtle error-by-one bug in the for loop (did anybody spot it???). Now thanks to Edit and Continue you can fix this bug without stopping and rebuilding. Whilst you're stopped on your breakpoint, change the for loop to the following and continue your application.
for (int i=0; i
continue now hit F5 and watch pure “magic” at work ...
It is simply brilliant!
I do not want to try and imagine what the poor compiler and the CLR have to do in the background to get this working, but they did so well done C# team! I know this kind of thing will save me many many hours of frustration and make me a much more productive developer.
Now if I could just somehow stop doing these silly things from the word go then all would be better!
Sure there are some things that you cannot do with Edit and Continue like;
- Add new methods
- Adding or removing parameters from a method
- Changing the name of a class or method
- etc.
But with what it gives us, already I'll be far more productive.
oh and before I get hammered on from the VB.NET development *cough* community, yes I know you've had this since VB3 or something, but I don't care; we've finally got in C# and that is all that matters ... well to me anyways :-D