Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ query on object with unknown class

I have an array of unknown (to the current method) class objects. I do know that each class has a property called "Number". I am trying to write a LINQ query where I am looking for the object with the next Number in sequence. AKA, I'm at Number 8, use a LINQ query to find the object where Number=9.

Anyone got a suggestion?

Also, I use reflection often so don't worry about avoiding it.

like image 794
Craig White Avatar asked Jan 20 '23 18:01

Craig White


1 Answers

You can create an interface - INumber with a property Number. Each of the objects that you are having in the array can implemen this interface.

That way, you will have an array of known type INumber. This way your query will be easy to debug and maintain.

like image 58
Sandeep G B Avatar answered Jan 30 '23 22:01

Sandeep G B