Visual Studio Tip – Named Parameters in Generated Methods

Really quick tip that I found recently while refactoring some old code.

If your using “Generate Method” (Ctrl + .) in Visual Studio, the method you’re generating uses the same names as the local variables for parameter names:

Generate Method without Named Parameters

Generate Method without Named Parameters

I don’t know about you, but I then have to spent more than a zero time tidying it up to be more meaningful. Thankfully named parameters can take care of that for you:

Generate Method without Named Parameters

Generate Method without Named Parameters

Seems to work for constructors and other refactors too.

Maybe it’s common knowledge, but it pleased me, so by putting it here I can remind myself in a couple years weeks time when I forget.

Leave a Reply

Your email address will not be published. Required fields are marked *