Methods
- Receives input from the parameters and output back using the return type.
- Can have void return type where it doesn’t return any value
- Method signature must be unique within the type
Modifiers
- Static : static
- Access modifiers: public, internal, private, protected
- Inheritance modifiers: new, virtual, abstract, override, sealed
- Partial: partial
- Unmanaged: unsage, extern
- Asynchronous: async
Expression-bodied methods (C# 6)
Expression-bodied method uses fat arrow to replace braces and return keyword and can also have void type.
int Foo (int x) { return x * 2; } equals to int Foo (int x) => x * 2; void method void Foo (int x) => Console.WriteLine (x);
Overloading methods
Methods with same name with different signatures and same return type
Pass-by-value versus Pass-by-reference
Whether a parameter is pass-by-value or pass-by-reference is also part of the signature.
Foo(int) can coexist Foo( ref int) or Foo(out int) but Foo(ref int) cannot coexist Foo(out int).