?
--
Imagine I have a class TypeX and a class TypeY that inherts TypeX.
public class typeX
{
....
}
public class typeY
: typeX
{
....
}
I also have an interface IX
public interface IX
{
typeX GetThing();
void SetThing(typeX x);
}
And a generic class ABC that implements IX and is defined like so
public class ABC<T>
: IX
where T : typeX
{
T val;
public T GetThing(){return val;}
public void SetThing(typeX x){val = x;}
}
Why is this code not valid? ABC<T> does implement the interface, due
to the fact that T must be of typeX (or derived from it)
public class typeX
{
....
}
public class typeY
: typeX
{
....
}
I also have an interface IX
public interface IX
{
typeX GetThing();
void SetThing(typeX x);
}
And a generic class ABC that implements IX and is defined like so
public class ABC<T>
: IX
where T : typeX
{
T val;
public T GetThing(){return val;}
public void SetThing(typeX x){val = x;}
}
Why is this code not valid? ABC<T> does implement the interface, due
to the fact that T must be of typeX (or derived from it)