CustomClass{
int ID;
int numberToSum;
float numToAverage;
}
IEnumerable<CustomClass> results = MethodToPopulateIEnumerable();
List<int> listOfIDs = MethodToGetListOfIDs();
What I wish to do with these, is take my IEnumberable<CustomClass> and select all the ones where the ID is in the List<int> listOfIDs, then I wish to sum the numberToSum value of this and save it in a variable and get the average of the numToAverage property and save it in a variable.
What is the most elegant way to do this ?
I think you are looking for something like this:
Query Syntax
Method Syntax
Calculations
Another alternate method which would allievate some of the performances concerns by fellow members, but still allowing the query to be linq-to-whatever friendly (
linq-to-entities,linq-to-sql):