Connecting Tech Pros Worldwide Forums | Help | Site Map

Method return type of a methond that returns different object types

Nerd
Guest
 
Posts: n/a
#1: Mar 16 '06
I have a function in C3 that returns different object types depending
on the paramter passed. What is the best way to declare the return type
if the objects types doesnot have a common parent class.

Can I use System.Object as the return type?

something like this

if (param1 =="1")
{
return(new object1())
}
else
if (param1 =="2")
{
return(new object2())
}


jim4u
Guest
 
Posts: n/a
#2: Mar 16 '06

re: Method return type of a methond that returns different object types


Yes, you can use System.Object as the return type. If the return type
does not have any common base class AND does not implement a common
interface, then returning System.Option is the best way.

Regards,

Jim

Nerd
Guest
 
Posts: n/a
#3: Mar 16 '06

re: Method return type of a methond that returns different object types


Thanks Jim for the help

Closed Thread