Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c#- method overloading question

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
0
0
IN
Hi Guys, i wanted to use optional parameters in c# but i read that it is not allowed...anyways i have something like this and it is not throwing an error...can someone please check whats wrong with this:

in the interface i have:
Code:
string UserList()
{
get;
}

string UserList(int flag)
{
get;
}

and in the class i have:
Code:
public string UserList
{
   get
   {
     return UserList(1);
   }
}

public string UserList(int flag)
{
   get
   {
     if (flag!=null) 
      {
       //do something
      }
      else
      {
      //do someother thing
      }
    }
}

[red]the error it throws is that class already has definition for UserList[/red]

any suggestions...thanks

-DNG
 
hmm..i figured out my problem...thanks for looking...

-DNG
 
And for future readers the problem was...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
unlike in Java, where Types, methods and fields may have the same name, its not the same with c#. this is what i read online:

"The name of a constant, field, property, event, or type must differ from the names of all other members declared in the same class."

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top