X hits on this document

PDF document

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

176 views

0 shares

0 downloads

0 comments

27 / 73

Overloaded Methods

Consider the following two Drive methods closely:

Visual Basic:

Public Function Drive() As String If m_make = "Oldsmobile" then Return "Chicago" Else Return "Toledo" End If End Function

Public Function Drive(ByVal make As String) As String If make = "Oldsmobile" Then Return "Chicago" Else Return "Toledo" End If End Function

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 each one must have a different set of parameters. 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.

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



Document info
Document views176
Page views176
Page last viewedTue Dec 06 20:50:43 UTC 2016
Pages73
Paragraphs821
Words15988

Comments