Reputation: 10805
I want to find an item in a collection on a fix index. i can remove an item like this
my_Order.OrderItems.RemoveAt(id - 1);
But i want to know this item in a variable before deleting how can i find this?
FoodItem fd= my_Order.OrderItems.
Upvotes: 0
Views: 57
Reputation: 7804
If the collection exposes an indexer, you could use it:
var element = my_Order.OrderItems[id -1]
If the collection does not expose an indexer you could use Enumerable.ElementAt()
:
var element = my_Order.ElementAt(id -1)
Upvotes: 3