문제

slightly different question about variance this time.

I take it from experimentation that C# does not allow you to override a virtual function with a contravariant function? If it does, how do you do it, since I keep getting "suitable method overload not found." If it isn't, why not? if the base class specifies that the value in will always be an int, and the sub-class can take an object, where is the problem?

Same to return types, should be covariant in their overrride signature

What languages allow you to do this? (C++/Java I am looking at you) and if they let you use, variance what types? (return type/argument list etc.)

Could you have multiple overrides? I don't see why not as long as the signatures were technically unique.

Why does C#/CLR not support method override co/contra-variance?

I read this and I see no answers to any of the questions. I know about generic variance, and I know it's awesome. I want to know about method signature variance, and not just in C#, but also in C#(i.e. including but not limited to). If it doesn't exist I would like a confirmation of this and an explanation(is it an implementation detail? is my type theory wrong? Is it just the CLR/C# happens to not support this particular feature? Is it something I haven't thought of since I don't have to deal with implementing the CLR, and therefore don't know specific complex details?)

도움이 되었습니까?

해결책

Found the answer, section 10.6.4 in the C# specification states that overrides must have the same signature

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top