1

I would like to use a Dictionary> with a small modification. Where Func<> can take 1 or more parameters of type double.

I would have liked to do something like this

Dictionary<string, Func<params double, double>>

Basically I would like to be able to call functions that look like this.

double Function1(double value);
double Function2(double value1, double value2);
double Function3(double value1, double value2, double value3);

Thanks

user1185305
  • 875
  • 2
  • 15
  • 26

1 Answers1

4

the params-keyword is only syntactical sugar when calling the function. basically the parameter is an array of values:

public double MyFunc(params double[] values) { // code has to handle a array of double values... }

So you simply have to define your dictionary as

Dictionary<string, Func<double[], double>>

If you still want to have this syntactial sugar, you should define some wrapper-function or an extension function to call the method like

public double Call(string key, params double[] values)
{
    return dic[key](values);
}
gofal3
  • 1,213
  • 10
  • 16