5 Replies - 4000 Views - Last Post: 25 December 2011 - 05:02 AM

#1 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Using statements location

Posted 15 December 2011 - 10:43 AM

So I've seen some write using statements inside the namespace and some outside the namespace...

Is that a style preference or is there some functionality to it?

If it's style what do you use?

example:

using System;

namespace testNamespace
{
}



vs

namespace testNamespace
{
using System;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Using statements location

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4490
  • View blog
  • Posts: 7,822
  • Joined: 08-June 10

Re: Using statements location

Posted 15 December 2011 - 11:32 AM

Well, it's mostly preference. If you were going to have multiple namespaces in the same file, and wanted different things exposed to each, you would put the using directives inside the namespace (important distinction: the ones at the beginning are called "directives", the ones in the code that define a scope for IDisposable objects are called "statements"). Otherwise, outside.

VS templates put them outside the namespace, so if there's an accepted style, that's it. Of course, if your instructor or company has a different style guide, follow it, but I like to stick with MS's recommended guidelines when I can.
Was This Post Helpful? 1
  • +
  • -

#3 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: Using statements location

Posted 15 December 2011 - 11:35 AM

I like to stick to the 'by the book (if the book is written by MS)' styles when I can, it's just that when I use nArrange a external tool for VS that arranges the code, puts it inside so I wondered 'Why is it doing that?', and thus this question came to be.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4490
  • View blog
  • Posts: 7,822
  • Joined: 08-June 10

Re: Using statements location

Posted 15 December 2011 - 11:46 AM

Personally, I don't bother with nArrange. I've already got VS shortcuts (Ctrk-K,D) and Resharper to handle that.
Was This Post Helpful? 0
  • +
  • -

#5 cilaes  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 75
  • Joined: 12-December 11

Re: Using statements location

Posted 24 December 2011 - 09:50 PM

View PostCurtis Rutland, on 15 December 2011 - 11:46 AM, said:

Personally, I don't bother with nArrange. I've already got VS shortcuts (Ctrk-K,D) and Resharper to handle that.

Clarify please? What exactly do thoe shortcuts do?
Was This Post Helpful? 0
  • +
  • -

#6 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: Using statements location

Posted 25 December 2011 - 05:02 AM

Ctrl + K, D = Formats the whole documents (makes it nicer)

This post has been edited by RexGrammer: 25 December 2011 - 05:02 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1