Skip to content

Commit 3779875

Browse files
committed
fixes
1 parent 66cb08e commit 3779875

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Diff for: Content/Chapter-10-methods/methods-overloading/methods-overloading.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Method Overloading
22

3-
In many programming languages like C# and Java the same method can be declared in **few variants** with the same name and different parameters. This goes by the term “**method overloading**”. Now let's see how to write these overloaded methods in C#.
3+
In many programming languages like C# and Java the same method can be declared in **few variants** with the **same name and different parameters**. This goes by the term “**method overloading**”. Now let's see how to write these overloaded methods in C#.
44

55
## Method Signature
66

7-
In programming methods are **identified** through the elements of their declaration: **name** of the method + a list of its **parameters**. These two elements define its specification, the so called “**method signature**”. It is defined by the **method name** and the **definitions of the method parameters** (their types).
7+
In programming methods are **identified** through the elements of their declaration: **name** of the method + a list of its **parameters**. These two elements define its specification, the so called “**method signature**”.
8+
9+
The **method signature** is defined by the **method name** and the **definitions of the method parameters** (only parameter types are considered, and the parameter names are ignored). Example:
810

911
![](/assets/chapter-10-images/16.Method-signature-01.png)
1012

11-
In this example the method's signature is its name (**`Print`**), together with its parameter (**`string text`**).
13+
In this example the method's signature is its name (**`Print`**), together with its parameter types (**`string`**).
1214

1315
If our program holds several **methods with the same name**, but with **different lists of parameters (signatures)**, we can say that we use **method overloading**.
1416

@@ -20,9 +22,9 @@ As we mentioned, if you use **the same name for several methods with different s
2022

2123
## Signature and Return Value Type
2224

23-
It is important to say that **the returned type as a result** of the method **is not a part of its signature**. If the returned type was a part of the signature, then the compiler doesn't know which method exactly to call.
25+
It is important to say that **the returned type as a result** of the method **is not a part of its signature**. If the returned type was a part of the signature, then the compiler doesn't know which method exactly to call (there is an ambiguity).
2426

25-
Let's look at the following examplewe have two methods with different return types. Despite that, Visual Studio shows that there is a mistake, because both of their signatures are the same. Therefore, when trying to call a method named **`Print(…)`**, the compiler can't know which of the two methods to run.
27+
Let's look at the following **example**: we have two methods with different return types. Despite that, Visual Studio shows that there is a mistake, because both of their signatures are the same. Therefore, when trying to call a method named **`Print(…)`**, the compiler can't know which of the two methods to invoke.
2628

2729
![](/assets/chapter-10-images/17.Method-overloading-02.png)
2830

0 commit comments

Comments
 (0)