471,326 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

Change return type in derived function

[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.

Dec 15 '05 #1
1 1504
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave Booker" <db******@newsgroup.nospam> wrote in message
news:E5**********************************@microsof t.com...
[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.

Dec 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

94 posts views Thread by John Bailo | last post: by
9 posts views Thread by Rob. | last post: by
12 posts views Thread by David Sobey | last post: by
13 posts views Thread by Stephen Walch | last post: by
12 posts views Thread by Michael Maes | last post: by
14 posts views Thread by dcassar | last post: by
3 posts views Thread by kikazaru | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.