Declaring a Method C# with Example
Every method has a unique signature consisting of a accessor (public, private, ...) ,optional modifier (abstract), a name and if needed method parameters. Note, that the return type is not part of the signature. A method prototype looks like the following: AccessModifier OptionalModifier ReturnType MethodName(InputParameters) { //Method body } AccessModifier can be public, protected, pirvate or by default internal. 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 some or no input parameters. to set parameters for a method, you should declare each one like normal variable declarations (like int a), and for more than one parameter you should use comma between them (like int a, int b). 0 Parameters may have default values. for this you should set a value for the parameter (like int a = ). if a parameter has a default value, setting the input value is optional. The following method example returns the sum of two integers: private int Sum(int a, int b) { return a + b; }