If all objects inherit from a known interface, you can direct them, for example.
var next = items.Cast<IHasNumber>.FirstOrDefault(x => x.Number == index + 1);
If it is not, you can use dynamic , for example.
var next = items.Cast<dynamic>.FirstOrDefault(x => x.Number == index + 1);
If you have control over the types, then I would have them implement the interface so that you can use the first method, which should be much faster than the second. In this case, your collection will probably be an IEnumerable<IHasNumber> for starters, and you donโt even have to drop it.
source share