Search

Please remove the useless params keyword in C# by Kevin Lam

Closed
as By Design Help for as By Design

1
Sign in to vote
3
Sign in to vote
Sign in
to vote
Type: Suggestion
ID: 91266
Opened: 7/29/2004 2:49:24 PM
Access Restriction: Public
0
Workaround(s)
May be I'm reading it in-correctly, but after reading the description of the params keyword and try it out. I do not see any value it add to the C# language.

Here is the descriptions clipped from MSDN:

     The params keyword lets you specify a method parameter that takes an argument where the number of
        arguments is variable.

     No additional parameters are permitted after the params keyword in a method declaration, and only one
     params keyword is permitted in a method declaration.


since parameter qualified with params are required to be a single dim array. But isn't an array by definition is variable in size? In my opinion the params keyword add nothing more to C# language except more typing. Please explain to me when one would use one form over another?

void foo(params int[] vars)
{
}

void foo(int[] vars)
{
}

Thanks
Details (expand)
Product Language
English
Version
Visual Studio 2005 Beta 1
Category
Language/Compiler
Operating System
Windows 2000 Advanced Server
Operating System Language
US English
Proposed Solution
remove the params keyword
Benefits
Faster Development
Improved User Interface
Other Benefits
Faster Development
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 7/30/2004 at 6:55 AM
Kevin

What about
void foo(int[] vars, params object [] extraVars)
{
}

You could call foo with just an array of ints, or with an array of ints and an optional number of extra arguments of ANY type. All the extra arguments would be assigned into the object array extraVars, and the method could process them as it needs to.

hope this helps.

SantoshZ
Posted by Microsoft on 7/30/2004 at 7:05 AM
Kevin

What about
void foo(int[] vars, params object [] extraVars)
{
}

You could call foo with just an array of ints, or with an array of ints and an optional number of extra arguments of ANY type. All the extra arguments would be assigned into the object array extraVars, and the method could process them as it needs to.

hope this helps.

SantoshZ