?
Solved

Method overloads

Posted on 2009-06-30
4
Medium Priority
?
198 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 2000 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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

770 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