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. – BartoszKP Feb 18 '16 at 22:17GetWeight<Giraffe>();
also doesn't make sense, but I'm guessing you don't see generic methods as pointless. – BartoszKP Feb 22 '16 at 14:10<Giraffe>
is certainly a parameter - specifically a generic type parameter. – Roman Starkov May 29 '17 at 19:32