What are the most common naming conventions in C#?

后端 未结 6 521
我寻月下人不归
我寻月下人不归 2021-01-06 22:52

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?

相关标签:
6条回答
  • 2021-01-06 23:28

    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()
            {
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-06 23:33

    MSDN provides Design Guidelines that spell this out in detail.

    0 讨论(0)
  • 2021-01-06 23:34

    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
    0 讨论(0)
  • 2021-01-06 23:40

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

    0 讨论(0)
  • 2021-01-06 23:46

    Check out Lance's page

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

    and

    Naming guidelines

    0 讨论(0)
  • 2021-01-06 23:53

    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.

    0 讨论(0)
提交回复
热议问题