I've got a List<string>
that contains duplicates and I need to find the indexes of each.
What is the most elegant, efficient way other than looping through all the items. I'm on .NET 4.0 so LINQ is an option. I've done tons of searching and connect find anything.
Sample data:
var data = new List<string>{"fname", "lname", "home", "home", "company"}();
I need to get the indexes of "home".
How about something like this
I myself needed to find and remove the duplicates from list of strings. I first searched the indexes of duplicate items and then filtered the list in functional way using LINQ, without mutating the original list:
You can create an object from each item containing it's index, then group on the value and filter out the groups containing more than one object. Now you have a grouping list with objects containing the text and their original index: