In C # , and Java are the same, you can create methods. The method described here is the functions, subroutines, processes, etc. in other programming languages.
There are two ways to create a method: one that does not return a value. One is a method that has a return value. Either way, it's really simple.
Example: definition and use of a method without a return value
Public Static void Main(string[] args)
{
Greetings(" Hello, very happy to know you!" ");
Console.ReadKey(true);
}
// Create a method with no return value
Public Static void Greetings(stringText1)
{
Console.WriteLine(Text1);
}
Example: the definition and use of a method that has a return value.
Public Static void Main(string[] args)
{
Console.WriteLine(addition(1,2));
Console.ReadKey(true);
}
// Define a method that returns the sum of two numbers
Public Static int addition(intNUM1,intnum2)
{
return(num1+num2);
}
Note: You may think that I cite the example is very simple, in fact, the main purpose is to let everyone understand and grasp, and not to let everyone confused. So, it is the purpose to speak clearly.
This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1970747
20, C # inside the creation and display of methods