I have a class that contains a variable of indeterminate type, which must be overridden at runtime, how can I do this?
Sorry for the disgusting question(
Example:
public class MyClass
{
public e_Type TypeValue;
public (variable of indeterminate type) Value;
}
public enum e_Type
{
string, int, bool, byte
}
At runtime variable TypeValue should determine the type of variable Value
It sounds like you’re really after generics:
Then you can create instances for different types:
This is still fixing the type at compile-time – but when the code using the type is compiled.
varis completely wrong here –varis just used for implicitly typed local variables. In particular, you can’t apply it to fields.It’s possible that you want
dynamic, but it’s not really clear from your question at the moment.