Reputation: 5660
I had to figure out a way to ask this that wasn't subjective, so this is specifically for Microsoft's coding style. In the ASP.NET MVC source, code files look like this:
// Copyright info
namespace System.Web.Mvc {
using System;
// blah blah
// ...
}
Note that 'using System' lines up nicely with the namespace. If I was to apply this style to my company's code, should I put 'using' statements for my company's namespaces directly below as well (so that it lines up)? When I put 'using' declarations at the top, I usually start with .NET namespaces first, so that's why I'm unsure. For example, should I do this:
namespace MyCompany.MyProduct.Something {
using System;
using MyCompany.MyProduct.SomethingElse;
}
or this:
namespace MyCompany.MyProduct.Something {
using MyCompany.MyProduct.SomethingElse;
using System;
}
I'm tempted toward the latter.
Upvotes: 1
Views: 571
Reputation: 7807
You've got two things going on here.
Order of using statements - Typically you will find the system namespaces first. Under that you will find a hierarchy of levels:
using System;
using System.Collections;
using System.Collections.Specialized;
Upvotes: 0
Reputation: 534
The convention I follow is:
Starting with wider scope towards narrower scope...
Upvotes: 0
Reputation: 8911
Microsoft StyleCop dictates using System.* first then your custom library namespace (i.e. the first option).
Upvotes: 1
Reputation: 564373
There is no single Microsoft style, although there have been attempts to consolidate their standardizations.
That being said, StyleCop forces all System namespaces to be listed first...
Upvotes: 7