I have a specialized list that holds items of type IThing
:
public class ThingList : IList
{...}
public interface IThing
{
Decimal
How about a generalised .Net 2 solution?
public delegate A AggregateAction( A prevResult, B currentElement );
public static Tagg Aggregate(
IEnumerable source, Tagg seed, AggregateAction func )
{
Tagg result = seed;
foreach ( Tcoll element in source )
result = func( result, element );
return result;
}
//this makes max easy
public static int Max( IEnumerable source )
{
return Aggregate( source, 0,
delegate( int prev, int curr ) { return curr > prev ? curr : prev; } );
}
//but you could also do sum
public static int Sum( IEnumerable source )
{
return Aggregate( source, 0,
delegate( int prev, int curr ) { return curr + prev; } );
}