01
- This slide is intentionally left blank - Some of the slides are based on University of Linz .NET presentations.
© University of Linz, Institute for System Software, 2004
published under the Microsoft Curriculum License
(http://www.msdnaa.net/curriculum/license_curriculum.aspx)<br>
02
FUN WITH C# EPISODE XIII TYPE INHERITANCE AWAKENS<br>
03
CLI Type System All types Reference types
(allocated on managed heap) Pointers Value types
(allocated in-place[with exceptions]) Classes(e.g. strings) Interfaces Arrays Delegates Simple types
(Int32, Int64, Double, Boolean, Char, …) Nullables Enumerations Structures User defined structures<br>
04
CLI Type Inheritance System.Object(C# keyword: object) user-defined classes(C# keyword: class) delegates(C# keyword: delegate) pointers(C#: Type *) System.Delegate System.MulticastDelegate System.ValueType System.Enum System.Array arrays(C#: Type[] or Type[,]) System.String(C# keyword: string) interfaces(C# keyword: interface) user-defined structures(C# keyword: struct) enumerations(C# keyword: enum) System.Int32(C# keyword: int) System.Int64(C# keyword: long) System.Double(C# keyword: double) System.Boolean(C# keyword: bool) … simple types System.Nullable(C#: Type?)<br>
05
Class System.Object Topmost base class of all other classes
class Object {
protected object MemberwiseClone() {...}
public Type GetType() {...}
public virtual bool Equals (object o) {...}
public virtual string ToString() {...}
public virtual int GetHashCode() {...}
public static bool ReferenceEquals(object objA, object objB);
}<br>
06
ValueType.Equals Override<br>
07
CLI Type Inheritance System.Object(C# keyword: object) user-defined classes(C# keyword: class) delegates(C# keyword: delegate) pointers(C#: Type *) System.Delegate System.MulticastDelegate System.ValueType System.Enum System.Array arrays(C#: Type[] or Type[,]) System.String(C# keyword: string) interfaces(C# keyword: interface) user-defined structures(C# keyword: struct) enumerations(C# keyword: enum) System.Int32(C# keyword: int) System.Int64(C# keyword: long) System.Double(C# keyword: double) System.Boolean(C# keyword: bool) … simple types System.Nullable(C#: Type?)<br>
08
Ref. Type DOES NOT Imply Instances System.Object(C# keyword: object) user-defined classes(C# keyword: class) delegates(C# keyword: delegate) pointers(C#: Type *) System.Delegate System.MulticastDelegate System.ValueType System.Enum System.Array arrays(C#: Type[] or Type[,]) System.String(C# keyword: string) interfaces(C# keyword: interface) user-defined structures(C# keyword: struct) enumerations(C# keyword: enum) System.Int32(C# keyword: int) System.Int64(C# keyword: long) System.Double(C# keyword: double) System.Boolean(C# keyword: bool) … simple types System.Nullable(C#: Type?)<br>
09
CLI Type Inheritance System.Object(C# keyword: object) user-defined classes(C# keyword: class) delegates(C# keyword: delegate) pointers(C#: Type *) System.Delegate System.MulticastDelegate System.ValueType System.Enum System.Array arrays(C#: Type[] or Type[,]) System.String(C# keyword: string) interfaces(C# keyword: interface) user-defined structures(C# keyword: struct) enumerations(C# keyword: enum) System.Int32(C# keyword: int) System.Int64(C# keyword: long) System.Double(C# keyword: double) System.Boolean(C# keyword: bool) … simple types System.Nullable(C#: Type?) Interfaces are not inherited from System.Object, but System.Object members are callable/accessible via any interface type expression.<br>
10
CLI Type Inheritance (Sealed Types) System.Object(C# keyword: object) user-defined classes(C# keyword: class) delegates(C# keyword: delegate) pointers(C#: Type *) System.Delegate System.MulticastDelegate System.ValueType System.Enum System.Array arrays(C#: Type[] or Type[,]) System.String(C# keyword: string) interfaces(C# keyword: interface) user-defined structures(C# keyword: struct) enumerations(C# keyword: enum) System.Int32(C# keyword: int) System.Int64(C# keyword: long) System.Double(C# keyword: double) System.Boolean(C# keyword: bool) … simple types System.Nullable(C#: Type?) sealed sealed sealed sealed sealed sealed sealed Optionally sealed<br>
11
Hiding Members can be declared as new in a subclass.
They hide inherited members with the same name and signature.
class A {
public int x;
public void F() {...}
public virtual void G() {...}
}
class B : A {
public new int x;
public new void F() {...}
public new void G() {...}
}
B b = new B();
b.x = ...; // accesses B.x
b.F(); ... b.G(); // calls B.F and B.G
((A)b).x = ...; // accesses A.x!
((A)b).F(); ... ((A)b).G(); // calls A.F and A.G!<br>
Show all 11 slides