Dhanapal
Dhanapal

Reputation: 14507

Unused 'using' directives are not shown as warning, any valid reason?

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

Is there any valid reason on this?

Upvotes: 3

Views: 396

Answers (2)

Mark Byers
Mark Byers

Reputation: 838376

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.

Upvotes: 7

Coding Flow
Coding Flow

Reputation: 21881

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

Upvotes: 1

Related Questions