Exercises in this lecture   Go to the notes, in which this exercise belongs -- Keyboard shortcut: 'u'   Alphabetic index   Course home   

Exercise solution:
Parameter variance


The program with the classes A/B/S/T is OK because the methods A.Op and B.Op are different from each other due to the rules about overloading. Recall that two methods of the same name, but with different formal parameter types, can coexist without problems in C#. When one of the methods are called, the static type of the formal parameters are used to find out, which of the methods to call.

Thus, aref.Op(sref) call A.OP, and not B.OP. And therefore there are no problems (no bomb) whatsoever.