I'd really like a a generic numeric type as the second generic type parameter of the Func<TInput, THere, TResult>
given below so I can provide either an integer or a double or a decimal as and when I like.
var _resultSelectors = new Dictionary<string, Func<DateTime, /*here*/ double, DateTime>>();
// so I can do
_resultSelector.Add("foo", (DateTime dt, int x) => ...);
_resultSelector.Add("bar", (DateTime dt, double d) => ...);
_resultSelector.Add("gar", (DateTime dt, float f) => ...);
_resultSelector.Add("har", (DateTime dt, decimal d) => ...);
Short of:
- making my own type; or
- using object and boxing a value type and unboxing it; or
- Using the
dynamic
keyword,
Is there a proper way to do that in C#?
I guess Java has a Number
class that probably fits in my requirements but I was wondering if C# has anything similar.
I guess there isn't any such thing in C# but I thought I'll ask to be sure.