What are the most common naming conventions in C#?

醉酒当歌 提交于 2019-11-30 19:58:24

问题


What are the most common naming conventions in C# for classes, namespaces and methods? Is it common to have getter/setter style methods as in Java?


回答1:


There are a few common patterns out there. One I frequently see and use in my own projects is:

namespace Company.Concept.SubConcept
{
    public class MyClass
    {
        private MyType someData;

        public MyType SomeData
        { 
            get { return someData; }
            set { someData = value; }
        }

        public void MyMethod()
        {
        }
    }
}



回答2:


Guidelines for Names (from Design Guidelines for Developing Class Libraries, in which you will also find sections about properties and choosing between properties and methods. In that last article, you will find the following:

Do use a property, rather than a method, if the value of the property is stored in the process memory and the property would just provide access to the value.




回答3:


No it is not common to use getter /setter style names in C#. Properties should be used for almost all places you would use a getter / setter in Java.

IMHO, the defacto standard for naming conventions comes from the Framework Design Guidelines. It's enforced by several tools (FxCop) and is the dominant style of many libraries including the BCL.

  • http://www.amazon.com/Framework-Design-Guidelines-Conventions-Development/dp/0321246756



回答4:


I think that most projects are using the IDesign CSharp Coding Standard




回答5:


Check out Lance's page

http://weblogs.asp.net/lhunt/pages/CSharp-Coding-Standards-document.aspx

and

Naming guidelines




回答6:


MSDN provides Design Guidelines that spell this out in detail.



来源:https://stackoverflow.com/questions/1228478/what-are-the-most-common-naming-conventions-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!