Created
December 3, 2018 13:50
-
-
Save mattumotu/7649984a01ff94e288a3d641ebc8b9a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IFetchThings fetcher = new ClientFetcher(); | |
object fetched = fetcher.Fetch(); // object is really a Client (Boxed as an object) | |
// let's convert the object to a client | |
Client c = (Client)fetched; // Unbox fetched into Client - performance hit | |
// the compiler can't see any problem with this | |
// and it works at run-time | |
// let's convert the object to a project | |
Project p = (project)fetched; // Unbox fetched into Project - performance hit | |
// the compiler can't see a problem with this | |
// but when it runs you get an InvalidCastException - Whoops |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment