Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the compiler saying a field is never used when it is? [closed]

Pursuing perfection so as to catch beaudaciousness (paraphrasing Vince Lombardi), I tried to rid a project of its sole warning, which was: c:\project\nrps\PoisonFoot\releases\6-4-0\hhs\frmPlatypus.cs(103,16): warning CS0169: The private field 'PDQClient.frmPlatypus.scanned' is never used

So I commented out that line:

private bool scanned = false;

...but then I got:

C:\Project\nrps\PoisonFoot\Releases\6-4-0\HHS\frmPlatypus.cs(3390): The name 'scanned' does not exist in the class or namespace 'PDQClient.frmPlatypus'

...in two places (in the same class where it's supposedly unnecessarily defined)

How was I able to hoodwink the compiler without even trying? How can I get rid of the warning without receiving an err?

like image 204
B. Clay Shannon-B. Crow Raven Avatar asked Nov 30 '22 01:11

B. Clay Shannon-B. Crow Raven


1 Answers

When csc(the C# compiler) says a field is never used, what it actually means is that you never read from the field. If you only write to a private member field the compiler deduces that the field is redundant. So, I'm gonna assume that in line 3390 of frmPlatypus.cs you are assigning to scanned, not reading from it, and that's why the compiler complains.

Also - line 3390? Really?

like image 153
Idan Arye Avatar answered Dec 16 '22 03:12

Idan Arye