[Mono-list] Default Arguments
Michael Malinak
mm@crushedice.com
Fri, 3 May 2002 10:28:26 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_00BA_01C1F28D.42A90C10
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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 -----=20
From: Chris J. Breisch=20
To: mono-list@ximian.com=20
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 =3D 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
------=_NextPart_000_00BA_01C1F28D.42A90C10
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2715.400" name=3DGENERATOR>
<STYLE>@font-face {
font-family: Verdana;
}
@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in 1.25in; }
P.MsoNormal {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: Verdana
}
LI.MsoNormal {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: Verdana
}
DIV.MsoNormal {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: Verdana
}
H1 {
FONT-SIZE: 16pt; MARGIN: 12pt 0in 3pt; FONT-FAMILY: Arial; TEXT-ALIGN: =
center
}
H2 {
FONT-SIZE: 14pt; MARGIN: 12pt 0in 3pt; FONT-FAMILY: Arial
}
A:link {
COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline
}
PRE {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Courier New"
}
P.Code {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Courier New"
}
LI.Code {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Courier New"
}
DIV.Code {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Courier New"
}
P.E-mail {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; COLOR: maroon; FONT-FAMILY: =
Verdana
}
LI.E-mail {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; COLOR: maroon; FONT-FAMILY: =
Verdana
}
DIV.E-mail {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; COLOR: maroon; FONT-FAMILY: =
Verdana
}
SPAN.NormalFont {
FONT-FAMILY: Verdana
}
P.code0 {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Courier New"
}
LI.code0 {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Courier New"
}
DIV.code0 {
FONT-SIZE: 10pt; MARGIN: 0in 0in 0pt; COLOR: black; FONT-FAMILY: =
"Courier New"
}
P.e-mail0 {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; COLOR: maroon; FONT-FAMILY: =
Verdana
}
LI.e-mail0 {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; COLOR: maroon; FONT-FAMILY: =
Verdana
}
DIV.e-mail0 {
FONT-SIZE: 9pt; MARGIN: 0in 0in 0pt; COLOR: maroon; FONT-FAMILY: =
Verdana
}
SPAN.normalfont0 {
FONT-FAMILY: Verdana
}
SPAN.emailstyle20 {
FONT-WEIGHT: normal; COLOR: maroon; FONT-STYLE: normal; FONT-FAMILY: =
Verdana; TEXT-DECORATION: none
}
SPAN.EmailStyle25 {
FONT-WEIGHT: normal; COLOR: maroon; FONT-STYLE: normal; FONT-FAMILY: =
Verdana; TEXT-DECORATION: none
}
DIV.Section1 {
page: Section1
}
</STYLE>
</HEAD>
<BODY lang=3DEN-US vLink=3Dpurple link=3Dblue bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>The standard C# solution for this is =
multiple=20
functions.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Another, somewhat frowned upon, way is =
to pass a=20
function an ArrayList that contains the parameters. This is quite =
a bit=20
more unreadable, and actually makes for more writing/checking of=20
code.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Michael</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A title=3Dcjbreisch@altavista.net =
href=3D"mailto:cjbreisch@altavista.net">Chris=20
J. Breisch</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dmono-list@ximian.com=20
href=3D"mailto:mono-list@ximian.com">mono-list@ximian.com</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, May 03, 2002 =
10:23 AM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Mono-list] Default=20
Arguments</DIV>
<DIV><BR></DIV>
<DIV class=3DSection1>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon">Is VB.NET the only .NET =
language that=20
can handle default (C++) or optional (VB) arguments? It =
doesn=92t appear=20
that C# can, unless I=92m missing something, and although MS C++ does =
support=20
default arguments, it does not support them for member functions of a =
managed=20
type.</SPAN></FONT></P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon"></SPAN></FONT> </P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon">So=85if I want to create a =
.NET class that=20
has a member function with default arguments, how do I do=20
so?</SPAN></FONT></P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon"></SPAN></FONT> </P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon">I ask, because I=92m trying to =
implement=20
parts of Microsoft.VisualBasic.dll, and I=92m working on the =
Collection=20
class. It=92s Add member is defined as follows (VB.NET=20
Syntax):</SPAN></FONT></P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: =
maroon"></SPAN></FONT> </P><PRE><B><FONT face=3D"Courier New" =
size=3D2><SPAN style=3D"FONT-WEIGHT: bold; FONT-SIZE: 10pt">Public Sub =
Add( _</SPAN></FONT></B></PRE><PRE><B><FONT face=3D"Courier New" =
size=3D2><SPAN style=3D"FONT-WEIGHT: bold; FONT-SIZE: 10pt"> =
ByVal </SPAN></FONT></B><I><SPAN style=3D"FONT-STYLE: italic"><A =
onclick=3DshowTip(this) href=3D"">Item</A></SPAN></I><B><SPAN =
style=3D"FONT-WEIGHT: bold"> As Object, _</SPAN></B></PRE><PRE><B><FONT =
face=3D"Courier New" size=3D2><SPAN style=3D"FONT-WEIGHT: bold; =
FONT-SIZE: 10pt"> =
Optional ByVal </SPAN></FONT></B><I><SPAN style=3D"FONT-STYLE: =
italic"><A onclick=3DshowTip(this) href=3D"">Key</A></SPAN></I><B><SPAN =
style=3D"FONT-WEIGHT: bold"> As String, =
_</SPAN></B></PRE><PRE><B><FONT face=3D"Courier New" size=3D2><SPAN =
style=3D"FONT-WEIGHT: bold; FONT-SIZE: 10pt"> =
Optional ByVal </SPAN></FONT></B>{ <I><SPAN =
style=3D"FONT-STYLE: italic"><A onclick=3DshowTip(this) =
href=3D"">Before</A> | <A onclick=3DshowTip(this) =
href=3D"">After</A></SPAN></I> }<B><SPAN style=3D"FONT-WEIGHT: =
bold"> As Object =3D Nothing _</SPAN></B></PRE>
<P class=3DMsoNormal><B><FONT face=3DVerdana size=3D1><SPAN=20
style=3D"FONT-WEIGHT: bold; FONT-SIZE: 9pt">)</SPAN></FONT></B></P>
<P class=3DMsoNormal><B><FONT face=3DVerdana size=3D1><SPAN=20
style=3D"FONT-WEIGHT: bold; FONT-SIZE: =
9pt"></SPAN></FONT></B> </P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon"></SPAN></FONT> </P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon">I could implement it in either =
C# or C++=20
with overloaded methods, which would accomplish the same thing, but =
wouldn=92t=20
BE the same thing. I could implement this in VB.NET if =
necessary, but=20
I=92d like to avoid that.</SPAN></FONT></P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon"></SPAN></FONT> </P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon">Any =
thoughts?</SPAN></FONT></P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon"></SPAN></FONT> </P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: =
maroon">  =
; =
=
-chris</SPAN></FONT></P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon"></SPAN></FONT> </P>
<P class=3DMsoNormal><B><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-WEIGHT: bold; FONT-SIZE: 9pt; COLOR: maroon">Chris J. =
Breisch,=20
<I><SPAN style=3D"FONT-STYLE: italic">MCSD,=20
MCDBA</SPAN></I></SPAN></FONT></B></P>
<P class=3DMsoNormal><FONT face=3DVerdana color=3Dmaroon =
size=3D1><SPAN=20
style=3D"FONT-SIZE: 9pt; COLOR: maroon"></SPAN></FONT> </P>
<P class=3DMsoNormal><FONT face=3DVerdana size=3D1><SPAN=20
style=3D"FONT-SIZE: =
9pt"></SPAN></FONT> </P></DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_00BA_01C1F28D.42A90C10--