X hits on this document

PDF document

“Beginning Visual C# 2005 Express Edition Video Series” - page 47 / 73

177 views

0 shares

0 downloads

0 comments

47 / 73

Overloading Methods

Consider the following two Drive methods closely:

C#:

public string Drive() { if (make=="Oldsmobile") { return "Chicago"; } else {

return "Toledo";

}

}

public string Drive(string _make) { if (_make=="Oldsmobile") { return "Chicago"; } else {

return "Toledo";

}

}

This is called Overloading the Method. We've overloaded it with two different ways of calling the function. We can either call it passing in no parameters, or call it passing in the _make. Each method returns a string, but the parameters and how the method works internally can be different. In order to overload a method, the method signature must be different. "Method Signature" is just a technical term that means for the unique set of input parameters in a method. Why would you overload a method? When you create classes, you don't always know how they might be used up front in your application. Sometimes you don't have all the data readily available to you that you would need to call a method, so you need options on how to call the method. Also,

Supplemental Readings for the Express Edition Videos Copyright © 2005 LearnVisualStudio.NET



Document info
Document views177
Page views177
Page last viewedTue Dec 06 22:09:32 UTC 2016
Pages73
Paragraphs821
Words15988

Comments