Change return type in derived function

G

Guest

[Using .NET2.0]
Is there any way to change the return types on a member function in derived
classes? E.g., something like:

public abstract class A
{
protected abstract Object f();
}

public abstract class B<T> : A
{
override protected abstract T f();
}

or

public class C : A
{
override C f();
}

or

public class D : A
{
new D f();
}

I.e., I want to specify a function in a base class or interface and clarify
its return type in derived classes without having to cast the return value in
users.
 
N

Nicholas Paldino [.NET/C# MVP]

Dave,

The only way to do this is to make A generic, such that:

public abstract class A<T>
{
protected abstract T f();
}

This would require you to genericize (if that's a word) every class that
derives from A<T>.

Hope this helps.
 

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