Method return type of a methond that returns different object types

N

Nerd

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())
}
 
J

jim4u

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top