I can come up with three ways to do this. The first is a loop with an if statement, I probably wonβt use this option.
The second is to use Linq for calculation, check this site if you do not know Linq http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx
You could probably use Lamda Expressions, but I'm not very good with them, and I'm not 100% sure how to do this, but I feel that Lamda Expressions is likely to give you the most elegant solution.
TheLukeMcCarthy
source share