Reputation: 2664
I have a list: List<myObject> myList
. It currently holds 3 myObjects. Given an int, I need to know how to find the index of any one of those objects so that I can use it elsewhere. I have tried using lambda statements but for some reason they absolutely do not want to work. I'm actually unsure if they're appropriate for this scenario. I have tried using myList's IndexOf, but I can't seem to get that to work, probably because I'm using custom objects.
If anybody can tell me how to accomplish this I would really appreciate it.
Upvotes: 0
Views: 93
Reputation: 48558
how about
var myobject = myList.ToArray()[myInt];
or just
var myobject = myList[myInt];
Upvotes: 2
Reputation: 1712
If you can give us some code that would help.
Without any more info, here is something you can try.
int indexFound = Array.IndexOf<myObject>(myList.ToArray(), objectToLocateIdexOf);
Upvotes: 0