Multiple parm signatures

  • Thread starter Thread starter proxyuser
  • Start date Start date
P

proxyuser

In Console.Writeline(...), for example, there are multiple signatures of the
form

Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

in addition to

Writeline(string format, params object[] arg)

Why do we need the first 4 if we have the last one?
 
proxyuser said:
In Console.Writeline(...), for example, there are multiple signatures of
the form

Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

Sorry, that is

Writeline(string format, object arg0)
Writeline(string format, object arg0, arg1)
Writeline(string format, object arg0, arg1, arg2)
Writeline(string format, object arg0, arg1, arg2, arg3)
 
In Console.Writeline(...), for example, there are multiple signatures
of the form

Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

in addition to

Writeline(string format, params object[] arg)

Why do we need the first 4 if we have the last one?

This is just a guess, but I am going to wager that variadic functions
have some additional and often-undesirable overhead, which is likely
why the most common overloads are provided.

My Google-fu is weak today, and I am not apparently able to confirm
that. Perhaps someone here who is more intimate with the .NET
framework or who has tested this idea can speak to it one way or
another?

--- Mike
 
proxyuser said:
In Console.Writeline(...), for example, there are multiple signatures of
the form

Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

in addition to

Writeline(string format, params object[] arg)

Why do we need the first 4 if we have the last one?

The formers are easier to use as the latter requires you to create an array
of objects.

The latter is to use when you have more parameters that any former will
accept.
 
In Console.Writeline(...), for example, there are multiple signatures of
the form

Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

in addition to

Writeline(string format, params object[] arg)

Why do we need the first 4 if we have the last one?

The formers are easier to use as the latter requires you to create an
array of objects.

No it doesn't, because of the params keyword. An array is RECEIVED by the
method, but you the programmer do not CREATE an array, you merely keep
adding parameters separated by commas.
 
Jeff Johnson said:
In Console.Writeline(...), for example, there are multiple signatures of
the form

Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

in addition to

Writeline(string format, params object[] arg)

Why do we need the first 4 if we have the last one?

The formers are easier to use as the latter requires you to create an
array of objects.

No it doesn't, because of the params keyword. An array is RECEIVED by the
method, but you the programmer do not CREATE an array, you merely keep
adding parameters separated by commas.

You're right. Plus, msdn says the formers are not cls-compliant.
 
Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

in addition to

Writeline(string format, params object[] arg)

Why do we need the first 4 if we have the last one?

The formers are easier to use as the latter requires you to create an
array of objects.

No it doesn't, because of the params keyword. An array is RECEIVED by the
method, but you the programmer do not CREATE an array, you merely keep
adding parameters separated by commas.

You're right. Plus, msdn says the formers are not cls-compliant.

Wait, what? Why wouldn't

Writeline(string format, object arg0)
Writeline(string format, object arg0, object arg1)
Writeline(string format, object arg0, object arg1, object arg2)
Writeline(string format, object arg0, object arg1, object arg2, object arg3)

be CLS compliant?
 
Christophe Lephay said:
The latter is to use when you have more parameters that any former will
accept.

Clearly. But it's also to use when you have the same number of parameters
as they accept.

Which reminds me of another question: if you use 1, 2, 3 or 4 parameters,
how do you even know which version of the function will be called? I have
to assume it is the non params version, or else what would be the point :-)
But how does the compiler determine that? Just curious.
 
Clearly. But it's also to use when you have the same number of parameters
as they accept.

Which reminds me of another question: if you use 1, 2, 3 or 4 parameters,
how do you even know which version of the function will be called? I have
to assume it is the non params version, or else what would be the point
:-) But how does the compiler determine that? Just curious.

My guess would be that in the parsing tree (or whatever propellerhead
structures are used in a parser--it's way over my head), the params version
of any function is placed last, so it will be the last to match, like the
default case of a switch statement.
 
Jeff Johnson said:
Writeline(string format, object arg0)
Writeline(string format, object arg1)
etc

in addition to

Writeline(string format, params object[] arg)

Why do we need the first 4 if we have the last one?

The formers are easier to use as the latter requires you to create an
array of objects.

No it doesn't, because of the params keyword. An array is RECEIVED by
the method, but you the programmer do not CREATE an array, you merely
keep adding parameters separated by commas.

You're right. Plus, msdn says the formers are not cls-compliant.

Wait, what? Why wouldn't

Writeline(string format, object arg0)
Writeline(string format, object arg0, object arg1)
Writeline(string format, object arg0, object arg1, object arg2)
Writeline(string format, object arg0, object arg1, object arg2, object
arg3)

be CLS compliant?

Ask msdn ! ;)

They say : "This API is not CLS-compliant. The CLS-compliant alternative is
WriteLine(String, array<Object>[]()[])."

here : http://msdn.microsoft.com/en-us/library/fc0cx9a5.aspx
 
proxyuser said:
Clearly. But it's also to use when you have the same number of parameters
as they accept.

Which reminds me of another question: if you use 1, 2, 3 or 4 parameters,
how do you even know which version of the function will be called? I have
to assume it is the non params version, or else what would be the point
:-) But how does the compiler determine that? Just curious.

Maybe the params version just involves some kind of conversion, making the
non params a more immediate candidate...
 
Wait, what? Why wouldn't

Writeline(string format, object arg0)
Writeline(string format, object arg0, object arg1)
Writeline(string format, object arg0, object arg1, object arg2)
Writeline(string format, object arg0, object arg1, object arg2, object
arg3)

be CLS compliant?

Ask msdn ! ;)

They say : "This API is not CLS-compliant. The CLS-compliant alternative
is WriteLine(String, array<Object>[]()[])."

here : http://msdn.microsoft.com/en-us/library/fc0cx9a5.aspx

Okay, only the LAST one, with the four objects. Still...weird.
 
Jeff Johnson said:
Wait, what? Why wouldn't

Writeline(string format, object arg0)
Writeline(string format, object arg0, object arg1)
Writeline(string format, object arg0, object arg1, object arg2)
Writeline(string format, object arg0, object arg1, object arg2, object
arg3)

be CLS compliant?

Ask msdn ! ;)

They say : "This API is not CLS-compliant. The CLS-compliant alternative
is WriteLine(String, array<Object>[]()[])."

here : http://msdn.microsoft.com/en-us/library/fc0cx9a5.aspx

Okay, only the LAST one, with the four objects. Still...weird.

They are intended to disappear in some future .net release, i guess...
 
Back
Top