Skip to content

Instantly share code, notes, and snippets.

@mattumotu
Created December 3, 2018 13:50
Show Gist options
  • Save mattumotu/7649984a01ff94e288a3d641ebc8b9a2 to your computer and use it in GitHub Desktop.
Save mattumotu/7649984a01ff94e288a3d641ebc8b9a2 to your computer and use it in GitHub Desktop.
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