R
Rene
We all know that we can't call custom methods or properties form generic
type parameters (<T>) by default because the compiler will complain about
his. For example, the following won't normally compile:
T.MyCustomMethod()
The compiler will tell me that it's not sure that the generic type
parameters (<T>) will contain such method and will requires me to constrain
the generic type parameters.
My question is. Why doesn't the compiler allow for things such as anonymous
methods or properties when using generic type parameters (<T>)? Why won't
the compiler assume that such method with such return type is declared on
<T> and then only complain when the type parameter *is* replace with the
actual object it was meant to be replace with? Why the absolute necessity to
constrain the type parameter?
Thanks.
type parameters (<T>) by default because the compiler will complain about
his. For example, the following won't normally compile:
T.MyCustomMethod()
The compiler will tell me that it's not sure that the generic type
parameters (<T>) will contain such method and will requires me to constrain
the generic type parameters.
My question is. Why doesn't the compiler allow for things such as anonymous
methods or properties when using generic type parameters (<T>)? Why won't
the compiler assume that such method with such return type is declared on
<T> and then only complain when the type parameter *is* replace with the
actual object it was meant to be replace with? Why the absolute necessity to
constrain the type parameter?
Thanks.