C# - Location of using statements

后端 未结 3 1069
逝去的感伤
逝去的感伤 2020-12-10 14:22

One thing I have noticed a lot of back and forth on is where using statements should be placed in a C# code file- whether its in the outermost scope or inside a namespace. I

3条回答
  •  不思量自难忘°
    2020-12-10 15:15

    edited, with my head hanging in shame

    Ahh! The using statement you're refering to is used to import a namespace, not to wrap an IDisposable object!

    Very different, ambiguous terms... you had me confused :-)

    Personally I like them outside the namespace at the top of the file; but it's probably due to me switching between C# and VB.NET.

    I like to organize my projects into 1-file-per-class, no inner (nested) classes, and only one class per namespace (per file) . In this situation the location of the using statement is irrelevant whether inside or outside the namespace.


    The iDesign C# coding standard is a solid standard to follow (or to derive your own from). It recommends keeping the using statements outside the namespace as item #14. But it's all down to your company / project's convention

提交回复
热议问题