'Fix' of unassigned local variable is bad
In 216 - when presented with a warning regarding an unused local variable
- e.g.:
public void Test()
{
foreach(MyClass thing in things)
{
int result = thing.DoSomething();
}
}
There is a warning that the variable 'result' isn't used - the auto-fix seems
to be to remove the line completely which is NOT desirable - what would be
desirable would be to remove the 'int result = ' - otherwise the (maybe important)
operation happening inside 'thing.DoSomething()' would be lost.
Ronnie
Please sign in to leave a comment.
Hello Ronnie,
We will provide two different quick fixes for such situation. One removes
the right part, the other leaves it.
Thanks,
Andrey Simanovsky
Hello Andrey,
That sounds great - which will be the default (first in the list) - presumably
the 'safer' one (ie leaving the right hand side).
Ronnie
>> In 216 - when presented with a warning regarding an unused local
>> variable - e.g.:
>>
>> public void Test()
>> {
>> foreach(MyClass thing in things)
>> {
>> int result = thing.DoSomething();
>> }
>> }
>> There is a warning that the variable 'result' isn't used - the
>> auto-fix seems to be to remove the line completely which is NOT
>> desirable - what would be desirable would be to remove the 'int
>> result
>> = ' - otherwise the (maybe important) operation happening inside
>> 'thing.DoSomething()' would be lost.
>> Ronnie
>>