Overloading methods - CSharp Custom Type

CSharp examples for Custom Type:Method

Introduction

A type may overload methods to have multiple methods with the same name), as long as the signatures are different.

For example, the following methods can all coexist in the same type:

void Foo (int x) {...}
void Foo (double x) {...}
void Foo (int x, float y) {...}
void Foo (float x, int y) {...}

Pass-by-value versus pass-by-reference

Whether a parameter is pass-by-value or pass-by-reference is also part of the signature.

For example, Foo(int) can coexist with either Foo(ref int) or Foo(out int).

However, Foo(ref int) and Foo(out int) cannot coexist:

void Foo (int x) {...}
void Foo (ref int x) {...}     // OK so far
void Foo (out int x) {...}     // Compile-time error

Related Tutorials