Library tutorials & articles
The Quick & Dirty .NET Guide to C#/VB OOP
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:
Related articles
Related discussion
-
Creating a Windows Service in VB.NET
by codet (102 replies)
-
VB.NET or C#?
by siddeshwar (3 replies)
-
An Introduction to VB.NET and Database Programming
by yen (12 replies)
-
VB/VB.NET
by surath (7 replies)
-
Adding carriage returns to text file
by Andrew_B (4 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum)
Events coming up
-
Oct
14
What’s New in Visual Studio 2008 Service Pack 1?
Birmingham, United Kingdom
“Service Pack? We’re calling it a Service Pack? Are you kidding??!?!” Visual Studio 2008 Service Pack 1 will release later in 2008 alongside .NET Framework V3.5 Service Pack 1 and, together, they represent a significant upgrade to Visual Studio 2008. There are enhancements across many areas of the .NET Framework such as data access, windows application development and web development and there are also corresponding changes in the development environment to support the new framework features.
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 to a dll? I cannot do it on the server. Do I do it on my local computer and then upload?
http://www.developerfusion.co.uk/show/4341/5/
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 therms and the class theory really feels like puting each part of the program into a separate box and then figuring out how to drill a way between them. I started to learn C++ OOP at least 20 time and after a couple of weeks I did not even had an idea what it is about (note: I am not a proffesional programmer)...
I believe that: "The use of a programming language should be as simple as a pie and the algorithm should be the part where people spend the most of their time..."
When I do C# programming I do all public and it works great for me. Simply keep it simple!!!
Is there any web page or book where I could find how to do Non-OOP C# programming?
Sincerely,
Gabor Gorcsos
Though from personal experience I'd say 99.99% of the time, you'd want private member variables and public properties...
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. - Building a Full-Featured Custom DataGrid Control. It's just one of those overlooked things. Oh well.
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 )
What you presented in your article is you declared public property,then made the (get,set) private)
I have put this simple comparison code , so please advice your point, What is the logic behind reversing the modifier(public to private and vis versa).
thanks
Ehx
// what is in the book (Begining Asp.Net Database using C# p 321)
private string Country;
public string Country
{
get{return _Country;}
set{Country= value;}
}
// what is in web article ( in your article)
public string Name;
private string _Name
{
get{return Name;}
set{Name= value;}
}