C#: Getting maximum and minimum values of arbitrary properties of all items in a list

前端 未结 8 1678
温柔的废话
温柔的废话 2021-02-02 13:19

I have a specialized list that holds items of type IThing:

public class ThingList : IList
{...}

public interface IThing
{
    Decimal         


        
8条回答
  •  忘了有多久
    2021-02-02 13:56

    If you were you using .NET 3.5 and LINQ:

    Decimal result = myThingList.Max(i => i.Weight);
    

    That would make the calculation of Min and Max fairly trivial.

提交回复
热议问题