我想寫使用lambda以下如何重寫以下?(C#3.0)
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++;
}
,但不知何故沒有能夠得到它的工作(編譯時錯誤)
Enumerable.Range(0, x.Count).Select(i =>
{
yhat = inter + (slp * x[i]);
res = yhat - y[i];
sum_res += res * res;
n++;
});
錯誤:無法從用法推斷方法'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable,System.Func)'的類型參數。嘗試明確指定類型參數。
需要幫助。
感謝