Declaration of methods in C #

Source: Internet
Author: User

Declaration of methods in C # (four elements)

    1. Access modifier: Public,private(default access modifier for method)
    2. return value types: void and non-void
    3. Method Name: Specification is the method name takes the verb, the first letter of each word capitalized.
    4. Method Body: Writing logical statements

1. Say the access modifier, and say it again.

Public: Common, under the same namespace, any class can be accessed, under different namespaces, to access, add the corresponding namespace, and add references.

Internal: Can be accessed in the current assembly.

Protected: Protected, accessible in child classes of parent and parent classes.

Private: It can only be accessed in the current class.

2. Return value type:

Void means that there is no return value, you cannot use return to return a specific value, but you can use return to terminate the current method;

Non-void must return a value of the specified type. However, with two exceptions, ① returns a method of type double, which can return a value of type float, or int. The ② return value is a method of the parent class type that can return a value of its child class type.

3. The name of the method: usually verbs, the first letter of each word should be capitalized.

4 Method Body: Write logical statements.

Declaration of methods in C #

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.