# Is this index selection useless? [closed]

I'm reviewing some code and I came across this:

// Select the last parameter in the list
if (parametersListBox.SelectedIndex > -1)
{
parametersListBox.SetSelected(parametersListBox.SelectedIndex, true);
}


ParametersListBox being a C# ListBox. Despite the fact that the comment is wrong, does this actually do something or is this just useless code?

It does appear to be useless but it might be firing some bindings that aren't setup correctly in the first place.

For more on set selected.

Only thing I can suggest is to comment it out and do some testing.

The check is needed, because SetSelected() would throw an ArgumentOutOfRangeException.

See reference source: http://referencesource.microsoft.com/System.Windows.Forms/a.html#fcae9a622a947f54 or read the documentation where it clearly states

Condition for ArgumentOutOfRangeException

The specified index was outside the range of valid values.