Presentation is loading. Please wait.

Presentation is loading. Please wait.

- This slide is intentionally left blank -

Similar presentations


Presentation on theme: "- This slide is intentionally left blank -"— Presentation transcript:

1 - 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 (

2

3 TYPE INHERITANCE AWAKENS
FUN WITH C# EPISODE XIII TYPE INHERITANCE AWAKENS

4 CLI Type System All types Value types Reference types Pointers
(allocated in-place [with exceptions]) Reference types (allocated on managed heap) Pointers Structures Enumerations Classes (e.g. strings) Interfaces Arrays Delegates Simple types (Int32, Int64, Double, Boolean, Char, …) Nullables User defined structures

5 CLI Type Inheritance pointers (C#: Type *)
System.Object (C# keyword: object) interfaces (C# keyword: interface) System.String (C# keyword: string) System.Array System.Delegate arrays (C#: Type[] or Type[,]) System.MulticastDelegate System.ValueType delegates (C# keyword: delegate) user-defined classes (C# keyword: class) simple types System.Int32 (C# keyword: int) System.Double (C# keyword: double) System.Int64 (C# keyword: long) System.Enum System.Nullable (C#: Type?) user-defined structures (C# keyword: struct) System.Boolean (C# keyword: bool) enumerations (C# keyword: enum)

6 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); }

7 ValueType.Equals Override

8 CLI Type Inheritance pointers (C#: Type *)
System.Object (C# keyword: object) interfaces (C# keyword: interface) System.String (C# keyword: string) System.Array System.Delegate arrays (C#: Type[] or Type[,]) System.MulticastDelegate System.ValueType delegates (C# keyword: delegate) user-defined classes (C# keyword: class) simple types System.Int32 (C# keyword: int) System.Double (C# keyword: double) System.Int64 (C# keyword: long) System.Enum System.Nullable (C#: Type?) user-defined structures (C# keyword: struct) System.Boolean (C# keyword: bool) enumerations (C# keyword: enum)

9 Ref. Type DOES NOT Imply Instances
pointers (C#: Type *) System.Object (C# keyword: object) interfaces (C# keyword: interface) System.String (C# keyword: string) System.Array System.Delegate arrays (C#: Type[] or Type[,]) System.MulticastDelegate System.ValueType delegates (C# keyword: delegate) user-defined classes (C# keyword: class) simple types System.Int32 (C# keyword: int) System.Double (C# keyword: double) System.Int64 (C# keyword: long) System.Enum System.Nullable (C#: Type?) user-defined structures (C# keyword: struct) System.Boolean (C# keyword: bool) enumerations (C# keyword: enum)

10 CLI Type Inheritance pointers (C#: Type *) System.Object (C# keyword: object) interfaces (C# keyword: interface) Interfaces are not inherited from System.Object, but System.Object members are callable/accessible via any interface type expression. System.String (C# keyword: string) System.Array System.Delegate arrays (C#: Type[] or Type[,]) System.MulticastDelegate System.ValueType delegates (C# keyword: delegate) user-defined classes (C# keyword: class) simple types System.Int32 (C# keyword: int) System.Double (C# keyword: double) System.Int64 (C# keyword: long) System.Enum System.Nullable (C#: Type?) user-defined structures (C# keyword: struct) System.Boolean (C# keyword: bool) enumerations (C# keyword: enum)

11 CLI Type Inheritance (Sealed Types)
pointers (C#: Type *) System.Object (C# keyword: object) interfaces (C# keyword: interface) System.String (C# keyword: string) System.Array System.Delegate sealed arrays (C#: Type[] or Type[,]) System.MulticastDelegate sealed System.ValueType delegates (C# keyword: delegate) user-defined classes (C# keyword: class) sealed Optionally sealed simple types System.Int32 (C# keyword: int) System.Double (C# keyword: double) sealed System.Int64 (C# keyword: long) System.Enum System.Nullable (C#: Type?) user-defined structures (C# keyword: struct) sealed System.Boolean (C# keyword: bool) sealed enumerations (C# keyword: enum) sealed

12 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!


Download ppt "- This slide is intentionally left blank -"

Similar presentations


Ads by Google