Considering the below code, is it a bug that I can return
IEnumerable<AnyTypeinstead of only IEnumerable<IFuas constrained in
the base class?
It is not possible to add a constraint to the concrete class
implementation of GetStuff as it errors saying that it inherits the
superclass constraint(s) (which makes sense).
interface IFu
{
int GetValue();
}
abstract class A
{
public abstract IEnumerable<TGetStuff<T>() where T : IFu;
}
class B : A, IFu
{
public override IEnumerable<TGetStuff<T>()
{
return (IEnumerable<T>)new List<object>(); //should this
generate a compile time error?
}
public int GetValue()
{
return 0;
}
}
class Program
{
static void Main(string[] args)
{
B b = new B();
foreach (IFu fu in b.GetStuff<B>())
{
Console.WriteLine(fu.GetValue());
}
}
}
TIA,
JB