How to unbox from object to type it contains, not knowing that type at compile time?
问题 At the run-time I get boxed instance of some type. How to unbox it to underlying type? Object obj; String variable = "Some text"; obj = variable // boxing; // explicit unboxing, because we know the type of variable at compile time. var x = (String)obj // Now let's pretend that we don't know the type of underlying object at compile time. Type desiredType = obj.GetType(); // But we can figure out. //And now the question. //How to express something like this: var y = (desiredType)obj; //Need to