Oct 23 2006

Optional Parameters in C#

Category:Bil@l @ 18:05

I have always heard that Optional parameters are not explicitly available in C#. Lately, I was reading the: Microsoft Visual C# Core Reference, while reading the section about Params keyword in C#, I got an idea that we can implement Optional Parameters in C# using the Params keyword.

Just to be on the safe side and you all know what Params means, it allows you to send to a method an array of unspecified number of arguments.

So make sure when you want to use the Params keyword to have it as the last item in the method parameters, because any parameter after it, will be collected as an array in the method body.