Calculate average in LINQ C# with string representation of property name

Posted by Paul on Stack Overflow See other posts from Stack Overflow or by Paul
Published on 2010-05-27T21:07:22Z Indexed on 2010/05/27 21:11 UTC
Read the original article Hit count: 119

Filed under:
|

I need to calculate a whole bunch of averages on an List of Surveys. The surveys have lots of properties that are int and double valued. I am creating a business object to handle all the calculations (there are like 100) and I'd rather not code 100 different methods for finding the average for a particular property.

I'd like to be able to have the UI pass a string (representing the property) and have the the business object return an average for that property.

So, like...

int AverageHeightInInches = MyObject.GetIntAverage("HeightInInches"); . . . Then have linq code to calculate the result.

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ