Class.Class vs Namespace.Class for top level general use class libraries?

后端 未结 7 1755
难免孤独
难免孤独 2020-12-11 07:52

Which one is more acceptable (best-practice)?:

namespace NP
   public static class IO
   public static class Xml
   ...
   // extension methods

using NP;

I         


        
7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 07:54

    I would say #1. Because when you bundle up lots of classes into one static class you do the same thing as a namespace is meant for. Which is why I would say it is best to let namespaces do that for you.

    In that case you can also get rid of having to write "NP" in front of everything by adding using in case you want. I think you should either nest your namespaces so that they wont collide or use more describing namespace names than IO.

    Most often the best practice is what Microsoft does and I have never seen them do #2

提交回复
热议问题