Maintain scope for a type that changes
<p>I have a simple bit of code where by I want to set a type depending on some data, but i cannot declare it before hand since i don't know what type it will be set to:</p>

<pre><code>if(data[i].on == true){
   Type1   temp  = (Type1)data[i];
} else {
   Type2   temp  = (Type2)data[i];
}
// scope lost
temp.call();
</code></pre>

<p>How do i maintain scope here? It's a bit confusing because i don't know what type i would have to set <code>temp</code> to before the if else statement.</p>

<p>Does C# have a solution for this ?</p>