I have a specialized list that holds items of type IThing
:
public class ThingList : IList
{...}
public interface IThing
{
Decimal
For C# 2.0 and .Net 2.0 you can do the following for Max:
public delegate Decimal GetProperty(TElement element);
public static Decimal Max(IEnumerable enumeration,
GetProperty getProperty)
{
Decimal max = Decimal.MinValue;
foreach (TElement element in enumeration)
{
Decimal propertyValue = getProperty(element);
max = Math.Max(max, propertyValue);
}
return max;
}
And here is how you would use it:
string[] array = new string[] {"s","sss","ddsffffd","333","44432333"};
Max(array, delegate(string e) { return e.Length;});
Here is how you would do it with C# 3.0, .Net 3.5 and Linq, without the function above:
string[] array = new string[] {"s","sss","ddsffffd","333","44432333"};
array.Max( e => e.Length);