I have a collection, and I'm trying to take the "last" item in the collection based on the following code:
return MyCollection.OrderByDescending(a => a.StartDate).FirstOrDefault(a => a.StartDate.Date <= DateTime.UtcNow.Date));
This works fine, but I ran into a problem when I have an example in which there are two entries in MyCollection with the same start date. (so I assume this arbitrarily takes one of them?)
to deal with this situation, I want to add a check for this, so if there are several elements with the same starting point, they then go to another field to decide which one needs to be returned, but I do not want to have the expense of checking this second field if the situation does not exist.
leora source share