(约定)C#类名 [英] (Conventions) C# Class names

查看:146
本文介绍了(约定)C#类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是太十分肯定我应该做的分组组类的东西。

I'm not too quite sure about what i should do about a grouped set of classes.

我的情况:我有11类,仅涉及到类 Character.cs ,但所有这些类的(包括 Character.cs CharacterManager.cs )是命名空间中 Models.Characters

My situation: I have 11 classes that relate only to the class Character.cs, but all of those classes (including Character.cs and CharacterManager.cs) are within the namespace Models.Characters.

这是命名类的更正确或首选方式:

Which is the more "proper" or preferred way of naming the classes:

(举例):

CharacterDetails.cs
CharacterSprites
CharacterAppearance
CharacterClientRights
CharacterServerRights

Details.cs
精灵
外观
ClientRights
ServerRights

(他们都注意到了 Models.Characters (所以如 Models.Characters.CharacterDetails Models.Characters.Appearance

(They're all noticed in Models.Characters (so eg. Models.Characters.CharacterDetails, Models.Characters.Appearance)

先谢谢了。

推荐答案

个人对我来说依赖。通常我会前缀字的一切字符让事情变得一致的,但是如果你有字符下方已经一切命名空间中的字符的前缀可能似乎是多余的。

Personally for me it"depends". Usually I would prefix everything with the word Character to keep things consistant, however if you have everything already under the Character namespace the Character prefix could seem redundant.

我可以很容易看到 Models.Character较短的约定去。[X] 如果有永远不会被调用另一个类详细信息,如果有例如可的UserDetails 然后详细信息的UserDetails 从现在回头看代码周或数个月的时候,我会个人更喜欢那么可能会造成混乱 CharacterDetails 选项。

I could easily see going with the shorter convention of Models.Character.[X] if there never will be another class called Details, if there for instance could be UserDetails then Details and UserDetails could be confusing when looking back at the code weeks or months from now and I would personally prefer then the CharacterDetails option.

在到底是你的个人喜好,有什么更加准确地描述您的域名,详细信息 CharacterDetails

In the end it is your personal preference, what more accurately describes your domain, Details or CharacterDetails?

这篇关于(约定)C#类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆