Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • I need example to know what is Downcasting ?
    – user184805
    Commented Oct 6, 2009 at 8:11
  • 5
    Avoid redefining well-established terms: “boxing”, in the context of OOP and C#, means something rather different (= wrapping a value type object into a reference). Also, your example could (and should) use the as operator instead of is, followed by a cast. Commented Oct 6, 2009 at 8:17
  • 3
    I stand corrected on the first point, and i changed the second half of my answer to show both ways of doing it.
    – RCIX
    Commented Oct 6, 2009 at 8:20
  • 4
    Your first statement ("...casting [an instance of Manager class] into an "employee" object [..] means you cannot access anything manager specific") is not completely accurate. In OP's example, if Employee has a virtual member that is overridden in Manager, the CLR will call the Manager implementation, notwithstanding the cast. From the MSDN article on polymorphism in C#: "When a derived class overrides a virtual member, that member is called even when an instance of that class is being accessed as an instance of the base class." The example provided by MSDN is almost identical.
    – Antony
    Commented May 11, 2013 at 4:35