Solved

Method overloads

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

Independent Software Vendors: 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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

724 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