C
C#3mo ago
cheeze2000

Compiler warnings about unused variables

I have a simple program
var a = 40;
var b = a;
var c = 20;

Console.WriteLine(a);
var a = 40;
var b = a;
var c = 20;

Console.WriteLine(a);
On my vscode, only c is underlined with this error: The variable 'c' is assigned but its value is never used Why is b not underlined? I mean it's dimmed but why isn't this a compiler warning as well?
No description
6 Replies
Nasdack
Nasdack3mo ago
The warning is issued if and only if the assigned value is a compile-time constant.
cheeze2000
cheeze2000OP3mo ago
i see thanks. do you know if there's any setting i can enable that detects b being unused
Nasdack
Nasdack3mo ago
b is already inspected and code analysis does tell that it is not being used
cheeze2000
cheeze2000OP3mo ago
what i mean is maybe it shows up as a compile-time warning
Nasdack
Nasdack3mo ago
You can configure the severity of this inspection It is not a compiler warning, and you can't force it to be one You can however configure IntelliSense or ReSharper to change its severity
cheeze2000
cheeze2000OP3mo ago
ok i'll look into it, thanks

Did you find this page helpful?