static void e() { Person p1 = new Person("1", "data"); Person p2 = new Person("2", "hata"); IComparable ic = Person.max(p1, p2); Person p = ic as Person; Console.WriteLine("{0} {1}", p.Name, "\n"); }
static void d() { Temp.MyDelegate d1 = new Temp.MyDelegate(f); Temp.MyDelegate d2 = new Temp.MyDelegate(f); Person p1 = new Person("1342", "anna"); IMyInterface imi = p1; Console.WriteLine(d1(p1, imi) == d1(p1, imi)); }
static void b() { Person p1 = new Person("1", "data"); p1 = new Test().bTemp(p1); IMyInterface2 imi = p1 as IMyInterface2; //Här, om man hade skrivit (p1.f("yes")) istället, så hade den använt den andra metoden f, mindre specifik Console.WriteLine(imi.f("yes")); }
static void c() { A a; Person p1 = new Person("1342", "anna"); a = p1; p1 = a as Person; Console.WriteLine((p1.f(p1.Name)).Equals("anna")); }
static void a() { Person p = new Person("1", "anna"); Person p2 = (Person)p.Clone(); //Nedan ger null reference fel, kan inte köra .print på null. //p2.print(); //kan istället skriva: p.print(); }