2
Reply

How to find index in linq query

    List ostring = new List();
    ostring.Add(“Archana”);
    ostring.Add(“P”);
    ostring.Add(“Parmar”);
    ostring.Add(“Check”);
    ostring.Add(“index”);

    1. IEnumerable<int> indexes = (from item1 in ostring
    2. where item1== "Check"
    3. select ostring.IndexOf(item1));
    4. Console.WriteLine(indexes.FirstOrDefault());

    //Hope you are looking for this //

    LINQ does not have an IndexOf method. So to find out index of a specific item we need to use FindIndex as int index = List. FindIndex(your condition);