By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,912 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,912 IT Pros & Developers. It's quick & easy.

generic interface question

P: n/a
Hello,

I have a question on why I am getting an error of "Cannot implicitly
convert type 'testGenerics.testCollection' to
'testGenerics.IMyCollection<System.IComparable>'. An explicit
conversion exists (are you missing a cast?)" for the following code.
Since, a Double implements IComparable, It should be implicitly
castable no?

interface IMyCollection<myTypewhere myType : IComparable
{

}

class testCollection : IMyCollection<Double>
{

}

class Program
{
static void Main(string[] args)
{
IMyCollection<IComparabletest = new testCollection();
}
}

Thanks,
Ning

Oct 30 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
>Since, a Double implements IComparable, It should be implicitly
castable no?
No. There's no inheritance relation between GenericType<Aand
GenericType<Beven if A derives from or implements B.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.