I am looking to create variables by string value. Is there smarter way to do it?
if (str == "DateTime")
{
DateTime d = new DateTime();
}
else if( str == "TimeSpan")
{
TimeSpan s = new TimeSpan();
}
I want to write something like that:
object o = new someString() ` when someString is "DateTime" or "TimeSpan"`
Os type will allways be justobject. So you can't do much with it. You'd have to cast it to the underlying runtime-type, which you don't know at compile-time.DateTimevalue actually have? Not as in "what is the value of the object" but more like "what do you intend to do with it, how is this useful for your program"? Same withTimeSpan, in both cases they will sort of have a "zero" value, or some default low value. I just don't see what you intend to do with these.