-
November 26th, 2010, 06:47 AM
#1
Generics, interfaces and casting
I hope this is the right forum for my question.
I am trying to write a generic class parameterized by an interface, and to down-cast an instance, but I always get an error. More exactly, I have the following:
Code:
interface IWhatever {... }
class IWhateverImpl : IWhatever { ... }
class CGeneric<T> where T:IWhatever { ... }
class Program {
CGeneric<IWhatever> mGeneric;
Program()
{
mGeneric = new CGeneric<IWhateverImpl>();
}
...
}
The typecast in line:
Code:
mGeneric = new CGeneric<IWhateverImpl>();
throws an exception.
Somehow I did not manage to google up this problem. Has anyone read anything about it, or has any idea about a solution / workaround to such a problem?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|