I need to find the index of a particular item with TValue list using Linq methods without using looping. I have tried to find index by comparing single TValue with a IEnumerable collection of Tvalue like below code
int idx= list.Select((elem, index) => new { elem, index }).First(p => p.elem == item).index;
With this, I am getting the following error
CS0019 Operator '==' cannot be applied to operands of type 'TValue' and 'TValue'
I have also tried Equals with this code but that too doesn't return exact index value.
int idx= list.Select((elem, index) => new { elem, index }).First(p => p.elem.Equals(item)).index;
Here, the list is a collection of TValue with 5 items and item is a TValue with a single item whose index is to be found within the list. Find the structure in below image
Please suggest a way to find index by comparing both TValue
Regards,
Keerthana.