❔ Why hasn't my class implemented the interface?

public interface IFoo
{
public IEnumerable<int> Get();
}

public class foo: IFoo
{
public List<int> Get()
{
return null;
}
}
public interface IFoo
{
public IEnumerable<int> Get();
}

public class foo: IFoo
{
public List<int> Get()
{
return null;
}
}
Given that List<int> is a subtype of IEnumerable<int> I don't see what the issue is here.
10 Replies
333fred
333fred2y ago
That's not how interface implementation works I mean, your link wasn't bad diddy There is a difference between overriding (that feature) and implementing (from an interface)
The Orange Tea Frog
What does this mean
333fred
333fred2y ago
Diddy posted a link, then deleted it
The Orange Tea Frog
oh I see Basically my question is why isn't public List<int> Get() an implementation of public IEnumerable<int> Get(); when List is a subtype of IEnumerable
333fred
333fred2y ago
Because that's not how implementations work It's the same type or nothing
The Orange Tea Frog
Ok what is the reason for that
333fred
333fred2y ago
To avoid unintentional implementation and ambiguities
The Orange Tea Frog
Fair enough, I suppose I can still just return a List
333fred
333fred2y ago
Correct
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server