|
-
Sep 30th, 2005, 03:13 PM
#1
Thread Starter
Fanatic Member
RE: Method Overloading
Hi,
can somebody give me a good example of method overloading in c#, and overloaded functions in c#, or even a pointers to a good language reference site for VS.net and all concernned languages?
cheers all
Kai
As the information I give is useful in its nature, consider using the RATE POST feature located on the bottom left of this post please..
A few things that make a good Developer a Great One.
Methodical and a thorough approach to research and design inevitably leads to success.
Forward thinking is the key to Flow of control.
Never test in the design environment, always test in real time, you get the REAL results.
CBSE & OOSE are the same animal, they just require different techniques, and thinking.
SEO is a globe of objectives, SE rankings is an end to a means for these objectives, not part of them.
The key to good design is explicit attention to both detail and response.
Think Freely out of the "Box" you're in..... You will soar to better heights.
Kai Hirst - MSCE, MCDBA, MCSD, MCP, MCAP, MSCT
-
Sep 30th, 2005, 08:59 PM
#2
Hyperactive Member
Re: Method Overloading
Method Overloading:
VB Code:
public class addNumbers
{
public int Add(int a, int b)
{
return a+b;
}
public int Add(int a, int b, int c)
{
return a+b+c;
}
}
-
Oct 1st, 2005, 03:06 AM
#3
Re: Method Overloading
Overloading is providing multiple implementations of a named method, where method signature is different for each one. Hence, the compiler determines which method to call based on the number and type arguments you pass.
To expand on fret's example:
Code:
public int Add(int a, int b)
The signature for this method is
whereas the signature for this method
Code:
public int Add(int a, int b, int c)
is
As the signature has to differ you cannot overload a method by merely providing arguments with different names as only the types are considered in the signature.
Hence, you can do this
Code:
public int Add(int a, int b)
{
return a + b;
}
public float Add(float a, float b)
{
return a + b;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|