Solved

Method overloads

Posted on 2009-06-30
4
193 Views
Last Modified: 2013-12-17
I have a method which I want overload (I hope that is the right term to use here).

However I want to overload the method with the same number of parameters.

For example

public bool AEvalidation(string PNo, DateTime DatePatJoined)
{
}

public bool AEvalidation(string PNo, int HouseNo)
{
}

This returned an error because I had the same number of overloads in my method.

Therefore I had no choice but to use

public bool AEvalidation(string PNo, DateTime DatePatJoined, bool CheckDigit)
{
}

This work around solved the porblem. But is there a better approach which I should have taken?
0
Comment
Question by:Mr_Shaw
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24747767
There must be something else with your code. Perhaps the error was about calling the method? Because your overloads are valid: when the signature of the parameters is different, it is good. As an example, consider:

public void testMe(bool value) {}
public void testMe(string value) {}
public void testMe(Uri value) {}

etc. The shown lines of your code seem correct. Can you show the exact error message your got with the exact line?
0
 

Author Comment

by:Mr_Shaw
ID: 24747788
What about this

public bool AEvalidation(string PNo, DateTime DatePatJoined){}

public bool AEvalidation(string PNo, DateTime DatePatLeft){}

How would one get arround the above code
0
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24747819
You cannot get around that code, because both are equal. There's no way the compiler can choose between the two based on the signature. How would you?
0
 

Author Closing Comment

by:Mr_Shaw
ID: 31598448
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now