7

Possible Duplicate:
Should Usings be inside or outside the namespace

Are there any technical reasons for preferring this

namespace Foo
{
     using System;
     using System.IO;

instead of the default

using System;
using System.IO;

namespace Foo
{
2

3 Answers 3

7

Eric Lippert explains this.

In general, they're identical.
However, using statements in the namespace can see namespaces and aliases included outside the namespace.

Sign up to request clarification or add additional context in comments.

Comments

2

Almost* the only difference between the two would be if you used more than one namespace in the same file (or if you used the same namespace more than once). I'm not sure why would you do that, bu you certainly can:

using System;

namespace FooNamespace
{
    using System.IO;

    class Foo
    {
        // you can use types from System and System.IO directly here
    }
}

namespace BarNamespace
{
    class Bar
    {
        // you can't use types from System.IO directly here
        // but you can use types from System
    }
}

* See SLaks' answer.

1 Comment

0

No technical reason, just a preference. of course the second chunk of code looks cleaner, though.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.