You can simply declare the variable as an object, and then cast it between your different types. This has performance implications due to late binding, but I think it may be better than having alot of references lying around on the stack.
Seeing as these references will be pointing to the same number of places on the heap as this single object reference would, then having just the single object reference on the stack should be better? Not sure on that one.
Short answer: Use a variable of type, 'object', to achieve your goal. I'm not positive on the performance implications.
This is all assuming that these variables you speak of are reference types, of course. If they're primitive value types, then I'd suggest just declaring temp vars of each type.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.