C # Object-Oriented Programming-method (4) of the newest Learning Series)

Source: Internet
Author: User

Method

In C #, create a function implementation method. The method is a member that executes computing or behavior by objects and classes. The method specifies the access level, return value, method name, and method parameter, declared in the class or structure, these parts are collectively referred to as the "signature" of the method. The access modifier is private by default.

Method format

If it is a method passing parameter, the data type must be declared. If the method has a return value, return must be used together with the return value to specify the exit point.

Access modifier return value type method name method parameter

[Modifiers] return_type MethodName ([parameters])

{

// Method body
}

Instance

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;

Namespace _ 4_Method
{
Class Program
{

// Method without Parameters
String GetName ()
{
Return "My name is sweet ";
}

// No return value, no Parameter Method
Void Worker ()
{
Console. WriteLine ("I am working ");
}
Static void Main (string [] args)
{
}
}
}

Related Article

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.