Retrieve index of a List<> item based in C# using Linq -


it pretty simple question, have list of object has field named "id".

how can retrieve index of object in list if know id?

example:

custom_objects test = new custom_objects{id=50}; list<custom_objects> list = new list<custom_objects>(); list.add(test); 

i retrieve index of object id = 50 in list, 0 in example.

var index = list.findindex(x=>x.id==50); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -