I need some help on simplifying my method
I have this method
public double ComputeBasicAmount(double basicLimit, double eligibleAmt)
{
return basicLimit * eligibleAmt;
}
sample usage:
Foo foo = new Foo(100, 1000);
double basicAmt = ComputeBasicAmount(foo.BasicLimit, foo.EligibleAmt)
The problem here is I want the eligibleAmt to be dynamic because sometimes
it’s not really only the eligbleAmt what I’m passing to the method.. like this
Foo foo = new Foo(100, 1000);
double basicAmt = ComputeBasicAmount(foo.BasicLimit, foo.EligibleAmt/foo.RoomRate)
My solution is use the Func delegate as a parameter but i don’t know how to use it properly
i want something functional like this
public double ComputeBasicAmount<T>(double basicLimit, Func<T, double> multiplier)
{
return basicLimt * multiplier;
}
double basicAmt = ComputeBasicAmount<Foo>(foo.BasicLimit, x => x.EligibleAmt/x.RoomRate)
can someone help me. thanks in advance…
If the multiplier depends on the item then either you’ll need to pass the item as well, or you’ll need to return a
Func<T, double>:or
If neither of those is what you were looking for, please explain where you want the actual value of
Tto be provided so that you can work out the multiplier.The first is very similar to just having a
Func<double>to compute the multiplier, of course… which in turn is pretty much like calling thatFunc<double>when computing the arguments, to get back to your original version which just takes two doubles.