The field X is assigned but its value is never used

ugh i hate this debug message. It just spams up the console and annoys me. I plan out my code carefully in advance, i implement things a piece at a time. this message always comes from half-implemented code and i find it frustrating.

is there any way to just turn it off? I still want to see other warnings, just not this one. If i want to optimise out unused variables i’d rather do that once, near the end of the development cycle.

If you don’t use it yet, comment it out.

i don’t read it, but i do write to it in many cases. populate things with values i’ll use later once i implement the system that needs them. Commenting it out often requires poking through the code and commenting 3-5 lines for each variable. it gets messy.

You can actually disable the warnings:

#pragma warning disable 0168// variable declared but not used.
#pragma warning disable 0219// variable assigned but not used.
#pragma warning disable 0414// private field assigned but not used.

Read more:
http://stackoverflow.com/questions/3820985/suppressing-is-never-used-and-is-never-assigned-to-warnings-in-c-sharp

5 Likes