Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Func<> - looking for an explanation - not a solution

Tags:

c#

i am using Math.net, among other methods i use integration, the integration function i use is defined as foloows:

public static double IntegrateComposite(
  Func<double, double> f,
  double intervalBegin,
  double intervalEnd,
  int numberOfPartitions)

yet, my call syntax is:

p = IntegrateComposite(
tau => MyFunction(r, tau, appCfg, Ta, Da) * ProbDensity(tau), 
lowLim, hiLim,  32)

My function is better defined as Func<double, double, double, double, double, double> and not the above Func<double, double>, still everything works fine Why?

like image 584
doronweiss Avatar asked Jan 26 '23 21:01

doronweiss


2 Answers

This is your the function you pass in, the only input argument is tau.

tau => MyFunction(r, tau, appCfg, Ta, Da) * ProbDensity(tau)

The other varibales r, appCfg, Ta, Da are 'closed over' by a closure

like image 82
gjvdkamp Avatar answered Jan 30 '23 06:01

gjvdkamp


Func<double, double> means

a function which takes 1 argument of type double in, and returns double

That's exactly what your arrow function does, no matter how many external variables are involved into calculation.

like image 33
Yeldar Kurmangaliyev Avatar answered Jan 30 '23 08:01

Yeldar Kurmangaliyev