Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 48,845 times

Contents

Related Categories

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

DMarko1

Parameters & 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:

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 desktop applications. Till now Jimmy has authored nearly two dozen .NET articles, published on Dot Net Junkies, 4 Guys From Rolla, Sitepoint, MSDN Academic Alliance, Developers.NET, The Official Microsoft ASP.NET Site, and here on Developer Fusion, covering various unique and advanced techniques on .NET.

Comments

  • Re: [4341] The Quick &amp; Dirty .NET Guide to C#/VB OOP

    Posted by Yoenuts on 25 Jul 2006

    hello,


    I am very impressed by your tutorial as it finally allowed me to grasp the syntax behind OOP programming with .net.
    Only what I did not understand is how and where do I complile the .cs ...

  • Re: [4341] The Quick &amp; Dirty .NET Guide to C#/VB OOP

    Posted by ggorcsos on 22 Jun 2006

    Honestly I believe that the basic idea of the OOP was really great, but to be able to use it one really has to have the head as a water melon. There is too much theory, too many ther...

  • Posted by James Crowley on 20 May 2005

    Though from personal experience I'd say 99.99% of the time, you'd want private member variables and public properties... ;)

  • Posted by DMarko1 on 22 Apr 2005

    Hi Ehx,

    That's true, and it's funny that in all my other articles I always write all private variables with public properties. i.e. - [url="http://www.developerfusion.co.uk/show/4676/1/"]Building a...

  • Confusion about this article (Get ,Set)

    Posted by aalhussein on 22 Apr 2005

    After reading your article, http://www.developerfusion.com/show/4341/6/
    I got realy confused!!

    from what I know from the book below, I declare private property, then declare public (get , set )
    W...