| co-contra-varians/ex.cs - The full C# program. | Lecture 8 - slide 3 : 37 Program 1 |
using System;
class S{
public void Sop(){
Console.WriteLine("Sop");
}
}
class T:S{
public void Top(){
Console.WriteLine("Top");
}
}
class A {
public void Op(S x){
x.Sop();
}
}
class B: A {
public void Op(T x){
x.Top();
}
}
class Client{
public static void Main(){
A aref;
B bref = new B();
S sref = new S();
aref = bref; // aref is of static type A and dynamic type B
aref.Op(sref); // B.Op is called with an S-object as parameter.
// What if an operation from T is activated on the S-object?
}
}