C # Object-oriented programming

Source: Internet
Author: User

Specification:

1. Do not place multiple classes in a source code file.

2. Name the source code file with the names of the public types that are included.

Property:

The key feature of a property is that it provides an API that looks like a field from an angle, but there is no such field in fact.

The auto-implemented properties are encapsulated in fields that do not now require additional code and may require additional validation in the future.

This way, although the declaration of a property changes, the calling code does not need to make any changes.

In the choice between an explicit assignment and a value method and a property, the general coding specification is that the method should represent the action, and the attribute is used to represent the data. Properties are designed to simplify access to simple data. What is expected in the encoding is that the cost of invoking the property should not be much higher than the Access field.

Specification:

To use attributes to simplify access to simple data (for a small amount of computation).

Avoid throwing exceptions from the property's accessor method.

To preserve the original property value when the property throws an exception.

Specification:

Use nouns, noun phrases, or adjectives to clearly attribute.

Consider having a property with the same name as its type.

Avoid naming fields with camel-cased styles.

If useful, append the Is/can/has prefix to the Boolean attribute.

Instead of declaring the instance fields of public or protected, the fields are exposed through properties.

To name attributes in Pascal case style

You prefer to use auto-implemented properties instead of fields.

If there is no additional implementation logic, prioritize the auto-implemented properties instead of writing the full version yourself.

As a good programming habit, you should only use the supported fields of properties within the property implementation, and do not call the fields directly until you have used the attributes. That way, as long as you add code to the property, such as validation code, the entire class can immediately take advantage of the code

Property and method calls are not allowed to be used as ref or out parameter values.

C # Object-oriented programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.