I have method which process the double arrays. I am supplying double arrays using keyword params. My problem is sometimesI have to pass doubles as well and I want to use to same method for both types. Currently method have signature
public void DoSomething(params double[][] arrays)
Above method definition works fine for following arguments:
double [] array = new double []{2,3,5} ;
double [] anotherarray = new double []{7,8,10} ;
DoSomething (array, anotherarray) ;
I am thing to pass object and then cast them in this method and use try catch block and I do not know it is right approach or there exists some elegant way to handle this kind of situation because I can have mixed data as input arguments.
public void DoSomething(params object objs)
{
// for loop
try
{
var tempdata = (double) objs(loop index);
double[] data = new double[] { tempdata };
}
catch
{
var tempdata = (double []) objs(loop index);
double [] data = tempdata;
}
// do other opertaion
}
I want to call this way:
double [] array = new double []{2,3,5} ;
double singlevalue = 10 ;
double [] anotherarray = new double []{7,8,10} ;
DoSomething (array, singlevalue, anotherarray) ;
double[][]and sometimes havedouble[], but those are the only options, then I would definitely suggest adding an overload (and making one overload call the other).floatis required yet - the OP isn't being very specific, but I can only seedouble[]andduoble[][]at the moment, which can definitely be handled with overloads. And yes, one overload would call the other, but that's fine.