tags:

views:

1094

answers:

3

Possible Duplicate:
Should Usings be inside or outside the namespace

sa1200 All using directives must be placed inside the namespace (StyleCop)

Is this just for code readibility or is there any actual advantage to doing so? Does it help the GC somehow?

A: 

There is no runtime difference. It's purely a compile time (and development experience) change. The file, compiled IL will be identical in either case.

Reed Copsey
Actually, there are rare cases where making that move can introduce a change in the generated code. http://blogs.msdn.com/ericlippert/archive/2007/06/25/inside-or-outside.aspx
Eric Lippert
Eric: Doesn't VS2008 catch that? I thought that now provided a compile-time warning/error. I know this was a problem in 2005...but I thought it was now caught.
Reed Copsey
You move a line of code from one place to another, how does the compiler know that the old way was "right" and the new way was "wrong"?
Eric Lippert
I thought it gave a warning that there was a possible ambiguity. Guess not.
Reed Copsey
A: 

If you have multiple namespaces in your project, you can limit which namespaces are used by each one individually.

This might come in handy if there were class names in two different namespaces that were the same. One might be the default in one part of your project, while the other could be the default in another.

Yes they look for some really fringe cases for these rules.

Brad Bruce
But you wouldn't have multiple namespaces in one file, would you? Because that would violate some other rule that I can't currently track down...
Mark