A simpler way to find the duplicate indexes that also handles more than #1 duplicate entry:
List<int> toremovestrs = new List<int>();
for (int i = 0; i < myList.Count; i++)
{
int first = myList.IndexOf(myList[i]);
string firststr = myList[first];
int last = myList.LastIndexOf(myList[i]);
if (first < last)
{
for (int j = first + 1; j <= last; j++)
{
if (myList[j] == firststr && ! toremovestrs.Contains(j))
{
toremovestrs.Add(j);
}
}
}
}
Test:
List<string> myList = new List<string> { "txt1", "txt2", "txt3", "txt1", "txt4", "txt5", "txt4", "txt2", "txt3", "txt4","txt10", "txt10" };
[0]: 3
[1]: 7
[2]: 8
[3]: 6
[4]: 9
[5]: 11