属性类型单数或复数,名称用尽 [英] Property types singular or plural, running out of names

查看:80
本文介绍了属性类型单数或复数,名称用尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#编写一个小型乐谱程序.我这样做的原因是为了证明我对c#有足够的了解,因为我最初是c ++的背景.

我已经阅读了c ++的历史,即clr的编写方式在c ++中,因此编码风格在设计上非常像c ++.然后,框架工作是由c#编写的,但是是由同一个人编写的,因此在设计上也是非常c ++的.之后,其他Microsoft人员开始使用它,并最终设计了编码对流.

我试图尽最大努力遵循它,但是提出了命名问题.例如:

公共枚举意外{自然,尖锐,平坦};

偶然的私人意外;

公共意外的意外

{
GET
{
返回偶然;
}


{
偶然=值;
}
}

现在,我发现已经制定了一条规则,规定枚举必须为单数,除非它们是标记,在这种情况下它们可以是复数.我想遵守约定,但是我应该如何命名该属性.

成员变量没有问题,但是如果枚举为单个,它将变为偶然的,在这种情况下,属性名称应该是什么

我可以说

public enum偶然的{自然,尖锐,平坦的};

public偶然的偶然
{

}

是可以接受的吗?我的班级称为Note,所以我必须将属性Name命名,因为您不能为该班级及其属性使用相同的名称.

我认为属性名称与变量名称或变量类型名称完全不同是不合逻辑的.

也不应放置成员变量和属性的名称在课程的同一部分.就是这样告诉我的.

在类,结构或接口中,元素必须按以下顺序放置:

字段

构造函数

终结器(析构函数)

委托

事件

枚举

接口

属性
索引器
方法

结构




有人可以在这里为我提供解决此问题的最佳方法吗?

I am writing a small music sheet program in c#. My reason for doing this is to demonstrate I know enough about c# to get a job in it as I am originally from a c++ background.

I have read the history of c++, i.e. how the clr was written in c++ so the coding style was very c++ in design. The frame work was then written in c# but by the same people, so it was also very c++ in design. After that other Microsoft people started using it and eventually a coding convetion was devised.

I'm trying to follow it as best as I can, but coming up with naming problems. For example:

public enum Accidentals {natural, sharp, flat};

        private Accidentals accidental;

        public Accidentals Accidental
        {
            get
            {
                return accidental;
            }

            set
            {
                accidental = value;
            }
        }

Now I find that a rule has been devised that says enum's must be singular, unless they are flag in which case they can be plural. I want to stick to the convention but how am I supposed to name this property.

The member variable is no problem but if the enum is singlur it becomes Accidental, in which case whats the property name supposed to be?

can I say

public enum Accidental {natural, sharp, flat};

public Accidental Accidental
{

}

is that acceptable?

Thinking up names for things can be hard work sometimes, but this makes it very difficult. My class is called Note so I had to make the property, Name, as you can't have the same name for a class and its attribute.

I don't think its logical to have totallly different names for properties than their variable or more specifically variables type names.

Also shouldn't member variables and properties be placed in the same section of the class. This is what I have been told.

Within a class, struct, or interface, elements must be positioned in the following order:

    Fields

    Constructors

    Finalizers (Destructors)

    Delegates

    Events

    Enums

    Interfaces

    Properties

    Indexers

    Methods

    Structs

    Classes


Can any one help me out here on the best way to resolve this problem.

推荐答案

公共枚举AccidentalType {自然,尖锐,平坦};

public enum AccidentalType {natural, sharp, flat};


这篇关于属性类型单数或复数,名称用尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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