Declaring a Method
suggest changeA method declaration has an access modifier, an optional modifier such as abstract, a return type, a name, and any parameters. The signature used for overloading is the name and the parameter types. The return type and the access modifier are not part of that signature. A method looks like the following:
AccessModifier OptionalModifier ReturnType MethodName(InputParameters)
{
//Method body
}
AccessModifier can be public, protected, private, or internal. A member of a class is private when the modifier is omitted.
OptionalModifier can be static, abstract, virtual, override, new, or sealed.
ReturnType can be void for no return or can be any type from the basic ones, as int to complex classes.
A method may have parameters. Declare each one as you would a variable (int a), and separate parameters with commas (int a, int b).
Parameters may have default values (int a = 0). If a parameter has a default value, the caller can omit it.
The following method example returns the sum of two integers:
private int Sum(int a, int b)
{
return a + b;
}