, :
for (int j = 0; j < AuthorCounter; j++)
. , = 0 j = 1, , = 1 j = 0. j i. = 0, , , AuthorGroupNodes.Nodes[0] . , AuthorGroupNodes.Nodes[1] . j + 1 == j. , node, j node. node j, , , j j, node:
for (int j = i + 1; j < AuthorCounter;)
{
if (AuthorGroupNode.Nodes[i].Text == AuthorGroupNode.Nodes[j].Text)
{
AuthorGroupNode.Nodes[j].Remove();
AuthorCounter--;
}
else
{
j++;
}
}
You say that this works, but not perfect, so I assume that you are not using a standard list and that your nodes handle their own removal from the list using the Remove () method.
If the list is sorted by the field you are comparing, you can completely remove the inner for loop and remove any duplicates of the current element until you find another:
for (int i = 0; i < AuthorCounter-1;)
{
if (AuthorGroupNode.Nodes[i].Text == AuthorGroupNode.Nodes[i + 1].Text)
{
AuthorGroupNode.Nodes[i].Remove();
AuthorCounter--;
}
else
{
i++;
}
}
source
share