Solved

Method overloads

Posted on 2009-06-30
4
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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!
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

726 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