Getting index of duplicate items in a list in c#

后端 未结 4 1437
星月不相逢
星月不相逢 2021-01-18 21:10

I am looking for a way to get the index of all elements in a list from a keyword search within the list. So for example my list has:

Hello World
Programming          


        
4条回答
  •  死守一世寂寞
    2021-01-18 21:49

    A little ugly but will work:

        var searchInList = new List();
    
    //Populate your list
    
        string stringToLookUp= "Hello world";
        var foundHelloWorldIndexes = new List();
    
        for (int i = 0; i < searchInList.Count; i++)
            if (searchInList[i].Equals(stringToLookUp))
                foundHelloWorldIndexes.Add(i);
    

提交回复
热议问题