How to rewrite the following?(C#3.0)

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-05-07T03:37:25Z Indexed on 2010/05/07 3:48 UTC
Read the original article Hit count: 162

Filed under:

I am trying to write the following

double sum_res = 0.0;
double yhat = 0;
double res = 0;
int n = 0;

for(int i=0;i<x.Count;i++)
{
    yhat = inter + (slp*x[i]);
    res  = yhat - y[i];
    n++;              
}

using lambda but somehow not able to get it work(compile time error)

Enumerable.Range(0, x.Count).Select(i =>
                {
                    yhat = inter + (slp * x[i]);
                    res = yhat - y[i];
                    sum_res += res * res;
                    n++;
                });

Error: The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Help needed.

Thanks

© Stack Overflow or respective owner

Related posts about c#3.0