2

R# tells me that a var is never assigned to.

I'm thinking, "if that's the case, just get rid of it - remove the declaration." But R#'s suggestions are different and varied:

enter image description here

Which knob should I turn, or should I just remain flatfooted and palely loitering?

Note: I didn't design or write this code, so I don't know what the intent is; there are some very strange Rube Goldbergesque "doings" amidst it all; to mix metaphors, I'm afraid of drawing a digit from the dyke or appending the straw that fractures the spine of the dromedary.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

2 Answers2

2

If you're unsure of what you're changing, don't change it! Especially if you think it might break something (I'd suggest getting the code under test before making any changes)

ReSharper is giving you a warning - you're completely free to ignore it. You can change the severity of the inspection to show as a hint, or not show at all. Or you can add special comments such as:

// ReSharper disable UnassignedField.Compiler

and

// ReSharper enable UnassignedField.Compiler

that will disable these warnings between the comments. The "Options for 'Unassigned field' inspection" submenu will have an option to generate the comments for you.

citizenmatt
  • 18,085
  • 5
  • 55
  • 60
2

If ReSharper is telling you that the field is not assigned, but is not offering to help you remove it, then that will be due to the fact that the field is not assigned, but that it is referenced.

Use "Find Usages" to find all references to the field. Then, keeping in mind that the field will always have its default value (false), ask yourself whether you shouldn't just replace all references to the field with the literal value false.

After you've done that with all references to the field, I'm sure that ReSharper will offer to have you remove the unused field.

John Saunders
  • 160,644
  • 26
  • 247
  • 397