Difference Between Shadowing and Override in C#
Posted On Friday, June 12, 2009 at at 2:15 PM by test
Difference between Shadowing and Override in C#
Criterion | Shadowing | Overriding |
---|---|---|
Purpose | Protecting against a subsequent base class modification introducing a member you have already defined in your derived class | Achieving |
Redefined element | Any declared element type | Only a procedure (Function or Sub) or property |
Redefining element | Any declared element type | Only a procedure or property with the identical calling sequence1 |
Accessibility | Any accessibility | Cannot expand the accessibility of overridden element (for example cannot override Protected with Public) |
Readability and writability | Any combination | Cannot change readability or writability of overridden property |
Keyword usage | Shadows recommended in derived class; Shadows assumed if neither Shadows nor Overrides specified | Overridable required in base class; Overrides required in derived class |
Inheritance of redefining element by classes deriving from your derived class | Shadowing element inherited by further derived classes; shadowed element still hidden2 | Overriding element inherited by further derived classes; overridden element still overridden |