<p>I have been trying to learn more about lambda expressions lately, and thought of a interesting exercise...</p>

<p>is there a way to simplify a c++ integration function like this:</p>

<pre><code>// Integral Function
double integrate(double a, double b, double (*f)(double))
{
    double sum = 0.0;

    // Evaluate integral{a,b} f(x) dx
    for(int n = 0 ; n &lt;= 100; ++n)
    {
        double x = a + n*(b-a)/100.0;
        sum += (*f)(x) * (b-a)/101.0;
    }
    return sum;
}
</code></pre>

<p>by using c# and lambda expressions?</p>

What about this:
```
```
public double Integrate(double a,double b, Func<double, double> f)
{
    double sum = 0.0;

    for (int n = 0; n <= 100; ++n)
    {
        double x = a + n * (b - a) / 100.0;
        sum += f(x) * (b - a) / 101.0;
    }
    return sum;
}
```
```
Test:
```
```
Func<double, double> fun = x => Math.Pow(x,2);        
    double result = Integrate(0, 10, fun);
```
```