The Quick & Dirty .NET Guide to C#/VB OOP

Overloading

Parameters

The concept of passing parameters is nothing new to OOP, and certainly not an incredibly difficult concept to grasp, since the same techniques were used when programming ASP/VB parameterized subroutines and functions. And what exactly are parameters? Values.

Shortly, as we explore Overloading , you'll simultaneously gain knowledge of this concept as well, if you didn't already.

Method Overloading

Method Overloading or Overloading is the means of re-implementing a method with the same name numerous times, providing its signatures (or number of parameter and or parameter reference types) are different.

To demonstrate, we'll now overload our ShowStats() method (taken from the Inheritance section code example) two different ways. Right after the default ShowStats method you can create overloaded methods, ready for implementation depending on your purpose like so:

public string ShowStats(string StartTxt){
  return base.Summary() + " - " + StartTxt + " it is located in " + Loc;
}

public object ShowStats(string StartTxt, string EndTxt){
  return base.Summary() + " - " + StartTxt + " it is located in " + Loc + " - " + EndTxt;
}

Our default ShowStats() method as noted before is the standard non-overloaded method. Above however, we've added an additional two methods, both overloading our default method. The first one a string method, accepts only one parameter StartTxt , thus its signature distinguishes it from its predecessor. The second pushes further by being an object method with two parameters , StartTxt and EndTxt. Both retrieving Loc from before as well.

And in our .aspx page we implement it, in addition to the way we did before, like this:

//Overloaded method 1
Response.Write (oHouse.ShowStats(" I think ") + "<BR><BR>");

//Overloaded method 2
Response.Write (oHouse.ShowStats(" I'm sure "," That's cool! ") + "<BR><BR>");

Same name, different signatures thus overloading, and our results:

You might also like...

Comments

About the author

Dimitrios Markatos

Dimitrios Markatos United States

Dimitrios, or Jimmy as his friends call him, is a .NET developer/architect who specializes in Microsoft Technologies for creating high-performance and scalable data-driven enterprise Web and des...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius