# Saturday, May 29, 2004

Some time ago I discovered a neat language feature of VB.NET where you can name parameters for method calls. This is actually something which has been around a long time even before .NET (was there anything before .NET? :) ).

Named parameters is a feature you can use if you want to be really explicit in your method calls it does actually improve readability somewhat.

As an example I had to code a components which would do transactions on people's credit card for Bolia.com because they have way too many transactions each week for them to handle it all manually.

The interface I was programming against looking something like:

 

Function Capture(ByVal sAmount As String, _

                         ByVal sTransact As String, _

                         ByVal sOrderid As String, _

                         ByVal bForce As Boolean, _

                        Optional ByVal sAccount As String = "") As Long

 

You can use named parameters if you want to be really explicit in your method calls it does actually improve readability somewhat. In the case I mentioned I wanted to make it really clear which values were used for what in the method call like this:

 

            Dim amount As String = "11111", transactionId As String = "11111"

Dim orderId As String = "11111", forceCapture As Boolean = True, accountNumber = "1111"

 

Capture(sAmount:=amount, sTransact:=transactionId, sOrderid:=orderId, bForce:=forceCapture, sAccount:=accountNumber)

 

Unfortunately C# does not support this but I guess that it goes against the whole philosophy of C# anyway :)

Friday, March 27, 2009 3:12:18 PM (Romance Standard Time, UTC+01:00)
It's true that this feature isn't in C# yet, but it will be in C# v4.0, so it's coming soon.
Comments are closed.