I was wondering why I can not have generic property in non-generic class the way I can have generic methods. I.e.:
public interface TestClass
{
IEnumerable<T> GetAllBy<T>(); //this works
IEnumerable<T> All<T> { get; } //this does not work
}
I read @Jon Skeet's answer, but it's just a statement, which most probably is somewhere in the specifications.
My question is why actually it is that way? Was kind of problems were avoided with this limitation?
class Figure { public ColorT Color<ColorT> { get { ... } } ... }
(possibly with some constraints onColorT
) to return color in a desired color space. Or quantities using different units, to refer to your example. – PsychroGetWeight<Giraffe>();
also doesn't make sense, but I'm guessing you don't see generic methods as pointless. – Psychro<Giraffe>
is certainly a parameter - specifically a generic type parameter. – FlowersWeight<Giraffe>
doesn't make sense. I pointed out, that this is pertains generic methods in the same way, so it cannot be a sensible reason for not having generic properties. – Psychro