With the following code:
string value = “1.2_3”;
int fieldStartIndex = value.IndexOf('.') + 1;
int fieldEndIndex = value.IndexOf('_');
if (fieldEndIndex == -1)
{
fieldEndIndex = value.Length;
}
int.TryParse(value[fieldStartIndex..fieldEndIndex], NumberStyles.Any, CultureInfo.InvariantCulture, out field);
‘field’ is used later in the function.
I’m getting “Warning S1854 Remove this useless assignment to local variable ‘fieldStartIndex’.” with both the Sonarlint VS plugin and Sonarqube 8.2.0.32929.
It happens at other uses of the ‘…’ range operator.