Thursday, November 20, 2008

C# 4 - Default Parameters

Coming from a C++ background, I'm really pleased that there'll eventually be default parameters built into the next version of C#. But I do think that C++ had a much cleaner way of handling them: it would only allow defaults from right to left, for instance:
void foo(int a, int b, int c=3, int d=4)
It wouldn't let you do:
void foo(int a=1, int b=2, int c, int d)
C# will, so for the example above, you'd end up with method calls that could look like:
foo( ,  , 3, 4)
One feature that I still really miss from C++ is const. This keyword could be applied to methods or parameters, so a method declared as:
void foo(int a, int b) const
{
}
would be guaranteed to not modify the state of the object (except for mutable members) A method declared as:
void foo (const Person person)
{
}
would be guaranteed to not modify the person. Maybe C# 5?

Wednesday, November 19, 2008

Adding folders to the Class View in Visual Studio

I didn't know this, but you can add folders to the Class View. You can then drag classes to it.   What's even better, you can drag methods to it!

Thanks to Sara Ford for her post describing this.

There's more good news! When you're editing code in the editor and you're over a class or method, you can use the 'Synchronise Class View' command (I've mapped mine to a keyboard short-cut, but you can add a toolbar item) to synchronise the Class View to the item you're currently editing.  Once synchronised, you can go to Class View and drag that into one of your folders.  Also, when you do this, you won't upset any of your team with changes to the solution or project files - because these are your settings, and hence are stored in the .suo file (which, on the other hand could be a pain, because user option files shouldn't be checked into your source repository).

Anyway, this is the next best thing to a 'bread-crumb' feature in the editor that let's you jump around to favourite places in the the code.   Maybe the bread-crumb feature will be in the next version of ReSharper?