The standard C# solution for this is multiple functions.
Another, somewhat frowned upon, way is to pass a function an ArrayList that contains the parameters.  This is quite a bit more unreadable, and actually makes for more writing/checking of code.
 
Michael
----- Original Message -----
Sent: Friday, May 03, 2002 10:23 AM
Subject: [Mono-list] Default Arguments

Is VB.NET the only .NET language that can handle default (C++) or optional (VB) arguments?  It doesn�t appear that C# can, unless I�m missing something, and although MS C++ does support default arguments, it does not support them for member functions of a managed type.

 

So�if I want to create a .NET class that has a member function with default arguments,  how do I do so?

 

I ask, because I�m trying to implement parts of Microsoft.VisualBasic.dll, and I�m working on the Collection class.  It�s Add member is defined as follows (VB.NET Syntax):

 

Public Sub Add( _
   ByVal Item As Object, _
   Optional ByVal Key As String, _
   Optional ByVal Before | After } As Object = Nothing _

)

 

 

I could implement it in either C# or C++ with overloaded methods, which would accomplish the same thing, but wouldn�t BE the same thing.  I could implement this in VB.NET if necessary, but I�d like to avoid that.

 

Any thoughts?

 

                                    -chris

 

Chris J. Breisch, MCSD, MCDBA

 

 

Reply via email to