Please Help!
What am I doing wrong?
static void f1(Color color, params float[] f) { System.Console.WriteLine("Here is f1 for float"); } static void f1(Color color, params int[] f) { System.Console.WriteLine("Here is f1 for int"); } static void Main() { f1(null,0); } I can't invoke f1(null,0); I get compile time error.
How this staff can be overcome assuming I indeed need those method signatures?
EDIT: As for Compile-tme error - ReSharper complains:
Cannot resolve method f1(null,int), candidates are:
void f1(Syste.Drawing.Color, params[] float)
void f1(Syste.Drawing.Color, params[] int)
0to either anintor afloat, but I've just tried your code in a test program and it compiles fine. This is because the0is assumed to be a 32-bit integer, so the second of the two methods is called. Can you post the compilation error you get so we have more information? EDIT: Refer to @meziantou's answer - it might be what your looking for.paramsis syntactic sugar which implicitly converts a comma-seperated list of values (which may be 0...n in number) into an array, so Michael Z's code is completely valid in that respect. Understand the details of the language before you answer.