A method in C# is a function defined inside a class that defines what an object can do.
This page covers Method in C#. For a language-agnostic introduction, see Method.
Defining a Method#
A C# method has an access modifier, a return type, a name, and a body.
public void Greet()
{
Console.WriteLine("Hello!");
}public— the access modifier;publicmeans the method can be called from anywherevoid— the return type;voidmeans the method returns nothingGreet— the method name; use PascalCase by convention()— the parameter list; empty here, but arguments go inside these parentheses
Return Types#
If a method produces a value, declare the return type instead of void and use return to send it back.