views:

63

answers:

2

Unused 'using' directives are not shown as warning [C#], why is it so?

Is there any valid reason on this?

+7  A: 

Eric Lippert talks about this in his blog post: Why are unused using directives not a warning?.

In summary it would cause lots of warnings that aren't really problems. The C# compiler tries to only warn you if there is actually a potential problem with the code. If there were too many unimportant warnings people would start to ignore them.

The automatic code generated by Visual Studio for example contains unused using statements and it would be annoying if that generated warnings.

Mark Byers
Wouldn't a "Message" (as opposed to an Error or Warning) be appropriate for this sort of thing?
Jesse C. Slicer
+1  A: 

The compiler omptimises them away anyway so they have almost no impact on anything.

Ben Robinson
'using' directives don't compile to anything. Their only purpose is so that you don't have to include the full name in all of your types. The compiler doesn't optimize them away since they don't compile to anything.
Wesley Wiser
Yes you are correct, i just meant that they have no effect on the compiled code.
Ben Robinson