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)
{
}
}
}