Solved

Method overloads

Posted on 2009-06-30
4
195 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

825 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