473,386 Members | 1,609 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,386 software developers and data experts.

inherited class instead of expected class in interface implementation

Why should the following not compile? ( it does not)

interface ISomething
{

Apples a {get;set;}
}
public class ChilieanApples:Apples
{
}

public class Apples
{
}
Class SomethingSpecific:ISomething
{
public ChilieanApples apples {get;set;}
}
Jun 27 '08 #1
2 1044
On May 9, 2:21 pm, parez <psaw...@gmail.comwrote:
Why should the following not compile? ( it does not)
Because C# doesn't support covariance of return types in terms for
interface implementation and member overriding. To override/implement
something, you have to supply exactly the same signature.

It's a pain, but that's the way it is.

Jon
Jun 27 '08 #2
On May 9, 9:38 am, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On May 9, 2:21 pm, parez <psaw...@gmail.comwrote:
Why should the following not compile? ( it does not)

Because C# doesn't support covariance of return types in terms for
interface implementation and member overriding. To override/implement
something, you have to supply exactly the same signature.

It's a pain, but that's the way it is.

Jon
Thanks.
I thought I mite have missed something because i expected it to
compile.

Jun 27 '08 #3

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

Similar topics

22
by: Marcin Vorbrodt | last post by:
Taken out of C++ In a Nutshell book... Example 7-18: Using an abstract classes as interface specification. struct Runnable { virtual void run() = 0; }; struct Hashable { virtual size_t...
9
by: Codex Twin | last post by:
Hi I have a common model for a Data Access Layer scenario. I have an abstract base class, called DalBase which contains a list of abstract methods. Lets call them: public abstract void Shine();...
4
by: Dan | last post by:
I have a need to make a set of classes that all share the same public methods, some implementation and some data. So, I made an abstract base (BaseClass) with an interface (IBaseClass) and a...
2
by: Wiktor Zychla [C# MVP] | last post by:
Hi, suppose there are two interfaces that contain methods with the same name but different signature: interface I1 { void F(); } interface I2 { int F(); } it is then easy to implement...
6
by: Peter Oliphant | last post by:
I just discovered that the ImageList class can't be inherited. Why? What could go wrong? I can invision a case where someone would like to add, say, an ID field to an ImageList, possible so that...
2
by: Walt Zydhek | last post by:
Could someone tell me how to Change the parameter type for an override of an inherited class member? In particular, I would like to change an indexer for my class that implements the IList class....
3
by: Matt F. | last post by:
I have an abstract class that about a dozen sub-classes inherit from. I want to enforce that each sub-class shadows an event in the abstract class, but can't quite figure out how to do this. ...
4
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a user control that is designed as below. I am creating these User Controls Dynamically in another form. They are multiple types of User Controls all with a common Interface so I can...
3
by: alan | last post by:
Hello all, I'm wondering if it's valid for a templated class to use a template parameter as a base class. Basically I have two abstract types, one of which is derived from the other, and I have...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.