Should a class have the same name as the namespace?

前端 未结 5 1537
陌清茗
陌清茗 2021-01-19 01:27

I\'m designing a namespace to hold a set of classes that will handle user related tasks for a several different applications. (Log-in, authenticate etc)

5条回答
  •  一整个雨季
    2021-01-19 01:48

    There are instances where using the same name will cause problems. One that leaps immediately to mind is when consuming a WCF service. When I did this recently in a class called "someBehaviour" in the namespace "companyName.someBehaviour" to consume "MyService", the compiler barfed on me saying that MyService didn't exist within the someBehaviour namespace. Changing the class name to something different (and vastly more useful) solved the issue and allowed me to compile the assembly.

提交回复
热议问题