C# 类命名约定
愚蠢的问题,但我已经很长时间没有用 C# 正确编码了,而且我已经忘记了我的命名标准并遇到了心理障碍,可以这么说!
我有一个可重用的类,将被 50 多个项目使用,我想给它一个合适的名称。 DLL 的命名空间正确(例如Client.PROJECT/PRODUCT.xxx.yyy
)。
我正在考虑将该类命名为“Common”,但想知道这是否有点太通用了?
Silly question but it's been a long time since I properly coded in C#, and I've forgotten my naming standards and run into a mental block, so to speak!
I have a reusable class that will be used by 50+ projects, and I want to give it a proper name. The namespace of the DLL is correct (e.g. Client.PROJECT/PRODUCT.xxx.yyy
).
I was thinking of naming the class as "Common" but was wondering if that was a little too generic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类名一般应表明该类的功能。 “Common”通常最好作为库名称的一部分(例如“Common.Logging”或“Ninject.Web.Common”),以指示该库中的文件对于特定用途是通用的,并且可能被使用由许多其他图书馆。
如果您想要更好地了解如何调用类,您需要分享有关您正在创建的类的目的的更多信息。但总的来说,考虑“消费者”的体验是件好事。例如,哪个更有意义?
... 或者:
The class name should generally indicate the function of the class. "Common" is generally better as part of the name for a library (e.g. "Common.Logging" or "Ninject.Web.Common") to indicate that the files within that library are common to a particular purpose, and likely to be used by a number of other libraries.
You'll need to share more information about the purpose of the class you're creating if you want better ideas for what to call the class. But in general, it's good to think of the "consumer's" experience. For example, which makes more sense?
... or:
通常,我对此类项目使用“Shared”或“Utils”。
一般来说,我不会向其中添加其他命名空间,例如,我更喜欢
Utils
而不是MyProject.Utils
,除非我修改Utils
以显式提供服务对于该项目,我将其重命名为MyProject.Shared
或MyProject.Utils
。希望这有帮助。
Usually, I use "Shared" or
Utils
for these kind of projects.And generally, I do not add other namespaces to it, e.g. I prefer
Utils
toMyProject.Utils
, Except when I modifyUtils
to serve explicitly for that project, then I rename it toMyProject.Shared
orMyProject.Utils
.Hope this helps.