Identical class names in different namespaces

前端 未结 6 1874
无人共我
无人共我 2021-01-11 13:33

I have two different namespaces, with lots of classes with the same name. I believe some code will make it easier to understand:

namespace Print.Pdl.PostScri         


        
6条回答
  •  南笙
    南笙 (楼主)
    2021-01-11 14:14

    Different namespaces are just that... Different, name, spaces so you shouldn't worry at all (generally) about duplicate names across namespace boundaries.

    However, you should be conscious of usage. e.g. you are creating a layered app with many different layers (in different namespaces), you would not want to duplicate class names that might be shared across layers.

    If you feel it is sensible to use duplicate naming between namespaces, you can always use the handy using statements for renaming in consuming classes e.g.

    you have two User classes :

    Data.Entities.User;
    App.Core.User;
    

    And want to use them in the same place...

    You can use a simple using statement such as

    using HttpUser = App.Core.User; 
    

    To alias one of them and so avoiding full qualification, and avoiding any confusion.

提交回复
热议问题