Check if object is higher in one list than in another

Viewed 51

I have the following situation:

    List<Driver> sortedDrivers = new List<Driver>();
    List<Driver> lastLapDrivers = new List<Driver>();

Each driver has the following properties:

    public string Name { get; set; }
    public int Pace { get; set; }

    public int Id { get; set; }

    public List<double> lapTime { get; set; }

    public double totalTime { get; set; }

    public int Position { get; set; }

    public Team Team { get; set; }

The difference between the two lists is that one list has the objects sorted different. What I'd like to see for each object in the the sortedDrivers list if it is higher in the list than it was in the lastLapDrivers list.

2 Answers

you can use the IndexOf(T item); method to get an index of an item in a list

example:

int myDriversIndex = sortedDrivers.IndexOf(myDriver);

Then you can compare that to it's index in lastLapDrivers, to determine which comes first.

Maybe Use A lambda Sum

var TotallastLapDrivers=lastLapDrivers.Sum(x=>x.lapTime );
var TotalsortedDrivers=sortedDrivers.Sum(x=>x.lapTime );

if(TotallastLapDrivers>TotalsortedDriverslastLapDrivers)
{
//do something
}

Hope That Helps!

Related