If I have a class with some value member that I want to store regardless of type, I would think that an object type would be the best. Lets say that the object can realistically be one of three types: string, int, customeClass. Would it be better to keep an extra enum member of the class with what type is stored in the value? Or is the execution of
if(object is string){...}
else if(object is int){...}
else if(object is customeClass){...}
fast enough that it’s not worth storing the extra information?
Don’t do premature optimization before measuring and proving that
isoperator is a local bottleneck on a hot code path. Maintaining the enum for the alternative approach will tax development over long time.