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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return type from a c# method 2

Status
Not open for further replies.

ace333

Programmer
Jul 12, 2005
105
CH
I am giving the user the option of calling a procedure or function from a c# method. The problem I have is that sometimes the procedure will return an int value and sometimes the method may return a string value or even a database. It depends on which procedure is called. Do I have to write the same method multiple times and call which ever one is needed each time or is there a way in c# too have the same method that returns multiple types depending in what is returned from the procedure.
 
What you are talking about is overloading.

Yes you will write a method for each return type.

Then the caller can use the method they need.
 
I'm not sure that you can return different types (as the return value) from an overloaded method. You can set up different parameters marked as ref or out and achieve this.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You can always pass back object and cast it as you need it as long as you know what type is coming back. The other option would be to create a class (bean) that contains information about the return type.
 
make the return type object

than the code that recieves the object just does a cast, this is sort of the reason theres a base class for all classes.
 
ya, all good ideas, thanks guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top