[Mono-list] Default Arguments

Brad Wilson dotnetguy@pobox.com
Fri, 3 May 2002 08:44:00 -0600

Chris J. Breisch wrote:

> 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):

I don't see a class named "Collection" anywhere in MSDN.net, so it's
impossible for me to know why or where this is used, but my initial guess is
that it's something that's only used from VB.net.

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

I _think_ you should be able to do this in C#:

   void Add(
      object Item,
      [Optional] string Key,
      [Optional,DefaultValue(null)] object Value

The OptionalAttribute class is part of System.Runtime.InteropServices; the
DefaultValueAttribute class is part of System.ComponentModel (which makes me
wonder whether that's right, because it would seem to be implying that it's
used for COM clients, not native .NET clients).

I have no idea what that "{ Before | After }" is, and why that parameter
doesn't have a name (I surmised that it's a value for dictionary-style
collection class and named it as such). The only reference I could find to
"Before" was in enumeration XmlNodeOrder.

Hope that helps,

Read my web log at http://www.quality.nu/dotnetguy/