473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Different return type of same method in interfaces having inherit

Hi every one.
I have two class: MyBase and MySon. MyBase is the base class of MySon. On
the other hand I have two interface: MyBaseItef and MySonItef. MyBaseItef is
the base interface of MySonItef. Now there has a GetMyClass method in
MyBaseItef liek: MyBase GetMyClass() in C#. If some class implement MySonItef
it must has GetMyClass Method. But the instance type of the return value is
MySon. Must I define an other method or use "new" keyword to override and
shadow the method in the base interface to change the type of the return
value. If I use "new" keyword, it must implement two methods of bouse
MyBaseItef and MySonItef in the class. And when some program load the
GetMyClass() method, both of the methods will be load. Who know how to change
the type of the return and not use "new" keyword and not use two method names.
Thanks.

Steven
13rd Dec 2004
Nov 16 '05 #1
1 2280
Steven.Xu <St******@discussions.microsoft.com> wrote:
I have two class: MyBase and MySon. MyBase is the base class of MySon. On
the other hand I have two interface: MyBaseItef and MySonItef. MyBaseItef is
the base interface of MySonItef. Now there has a GetMyClass method in
MyBaseItef liek: MyBase GetMyClass() in C#. If some class implement MySonItef
it must has GetMyClass Method. But the instance type of the return value is
MySon. Must I define an other method or use "new" keyword to override and
shadow the method in the base interface to change the type of the return
value. If I use "new" keyword, it must implement two methods of bouse
MyBaseItef and MySonItef in the class. And when some program load the
GetMyClass() method, both of the methods will be load. Who know how to change
the type of the return and not use "new" keyword and not use two method names.


You basically can't, currently. You will be able to for delegates only
with C# 2.0, but there's no way of doing it at the moment,
unfortunately.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

94
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it...
7
by: Jeffrey E. Forcier | last post by:
I am attempting to write a class whose string representation changes in response to external stimuli. While that effect is obviously possible via other means, I attempted this method first and was...
8
by: Martin Stettner | last post by:
Hi, I would like to use covariant return types in mutual dependent classes like: class IB; class IA { virtual IB* getIB() = 0; }; class IB{ virtual IA* getIA() = 0;
5
by: Wysiwyg | last post by:
I'm new to c# programming and can't figure out how to avoid duplicating common code in multiple classes when I'm restricted to using different system base classes.. I'm using c# in asp.net to write...
8
by: AAJ | last post by:
Hi all I would like to have a class that can set/return values of different datatype via a single accessor, i.e. overload the accessor i.e. something like DateTime m_DateValue; string...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
1
by: adesoky | last post by:
I have a class that inherit from two interfaces, each interface has one method but the signatures of the two interfaces' methods are identical. How I can implement each method in the class...
7
by: WTH | last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference the same interface from the same file in two different projects the types are actually incompatible. I found this out...
9
by: raylopez99 | last post by:
Here are two different ways of achieving a mediator pattern: the first, using circular references (for lack of a better way to describe it), but not using delegates, with the second using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.