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
-
hey developers out there
by pitsophera (0 replies)
-
How can i develop opc server using .net?
by vairajaig (1 replies)
-
Creating a Windows Service in VB.NET
by davidvanr (108 replies)
-
High-Performance .NET Application Development & Architecture
by Manjot Bawa (0 replies)
-
An Introduction to VB.NET and Database Programming
by carlosmen (14 replies)
Related podcasts
-
A Practical Look at Silverlight 2 Part 1
Now that Silverlight 2 is at the Olympics and making a big splash, we wanted to explore this fascinating technology more. Microsoft Silverlight 2 is a cross-browser, cross-platform, and cross-device plug-in for delivering the next generation of .NET based media experiences and rich interactive ap...
Events coming up
-
Nov
18
15 Minutes of Fame
Dresher, United States
This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.
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;}
}
This thread is for discussions of The Quick & Dirty .NET Guide to C#/VB OOP.