I am beginner at using lambda expressions.
I have a list of dealers, foreach dealer I have to calculate grade.
The request is that the grade calculation to be separated into a separate method.
So I am writing the below two methods, however I am unable to pass parameters to CalculateGrade() method,
public IEnumerable<Dealers> GetDealerGrades(IEnumerable<Dealers> gradeData)
{
return gradeData
.GroupBy(row => new { row.Name })
.Select(g => new Dealers
{
Name = g.Key.Name,
TotalPoints = CalculateGrade(x => Convert.ToDouble(x.RecievedPoints),
y => y.MaxPoints,
z => Convert.ToDouble(z.Weightage))
})
.ToList();
}
private double CalculateGrade(double d1, int d2, double d3)
{
return ( d1 / d2 )
* d3 == 0.00 ? 1
: d3;
}
Can somebody advise how to pass parameters in this , or how to pass lamda expressions and calculate grade?
Many thanks in advance...
.GroupBy(row => new { row.Name })can be written as.GroupBy(row => row.Name), nonewnecessary.g.Key.Nametog.Key