Creating your own methods that have optional parameters

I'd rather overload.

Code:
Public Function myMethod () as string
Public Function myMethod (aParm as string) as string
Public Function myMethod (anObj as object) as string
 
That is probably VB and I don't think you quite know what I mean. I guess the only way is to use method overloading, right?

I see someone already posted that. Ok, got my answer.
 
aewarnick said:
That is probably VB and I don't think you quite know what I mean.
It works in VB.NET, being a .NET related forum, I generally try to provide answers that work in .NET.
I guess the only way is to use method overloading, right?
Ummm... NO. Method overloading is probably a better approach to getting the functionality you require, but the Optional keyword is there just as I said above -- it is exactly what you asked for btw.
 
Do you have any idea how I would write that optional parameter in C#? I tried a few things but could not get it to compile.
 
C# doesn't support Optional parameters, your only choice is to use function overloading (a better design anyway).
 
Back
Top