Something like:
public static void Estimate ( params string [ ] names, params int[] numbers )
{ }
where you could use it like:
Estimate ( "Eric", "Simpson", "Jon", 1, 2, 3, 4, 5 )
Something like:
public static void Estimate ( params string [ ] names, params int[] numbers )
{ }
where you could use it like:
Estimate ( "Eric", "Simpson", "Jon", 1, 2, 3, 4, 5 )
As already discussed in the comments - this would be a nightmare for compiler writers and for the authors of the specification as well :-). (overload resolution in C# is already complicated enough)
One possible solution when you need something like this in practice is to just give up and use a single params
parameter of type object[]
. This may not be very elegant, but it allows you to do what you need. The compiler will not check whether all uses are correct, but it may still be reasonable...
For example, constructors of LINQ to XML types (e.g. XElement
) usually do this, so that you can create XElement
containin other elements, attribtues, collections of elements, etc..
new XElement( new XElement("elem"),
new XAttribute("attr", "value"),
GetListOfElements() );
Tomas and Kirk are right, this would be difficult to resolve and, even more so, it would potentially produce unexpected behavior from the point of the developer using it. For example, take the following class:
public class Overload<T, U>
{
public void SomeMethod(params T[] arrayOfT, params U[] arrayOfU) { }
}
Allowing multiple parameters using the 'params' keyword in a method would make this compile just fine, and would work fine for quite a few cases until someone tried to use the class as Overload<string, string>
(or something similar) and then a compilation error would happen. Another difficulty is that a parameter marked with the 'params' keyword allows the omission of that parameter when calling the method. For example, the following is also impossible to resolve adequately if the method is called with no parameters or even with several int values.
void SomeOtherMethod(params string[] arrayOfString, params int[] arrayOfInt);
void SomeOtherMethod(params int[] arrayOfInt);
Language features are generally added if there is a distinct benefit to them being there. Will they make things easier or just impede progress? This is a clear impediment, and one that can be gotten around by doing like Tomas suggested and using a params object[] parameter. You can also pass individual arrays (i.e. SomeOtherMethod(string[] arrayOfString, int[] arrayOfInt)), if separating by type works better for you.