using System;
public class Test
{
public static void Main()
{
Type t = typeof(int?); //will get this dynamically
Type u = Nullable.GetUnderlyingType(t);
object val = 5; //will get this dynamically
object nVal = Convert.ChangeType(val, u);// nVal will be 5
Console.WriteLine("Type is: {0}, Value is: {1}", nVal.GetType(), nVal);
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGNsYXNzIFRlc3QKewoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewogICAgICAgICAgICBUeXBlIHQgPSB0eXBlb2YoaW50Pyk7IC8vd2lsbCBnZXQgdGhpcyBkeW5hbWljYWxseQogICAgICAgICAgICBUeXBlIHUgPSBOdWxsYWJsZS5HZXRVbmRlcmx5aW5nVHlwZSh0KTsKICAgICAgICAgICAgb2JqZWN0IHZhbCA9IDU7IC8vd2lsbCBnZXQgdGhpcyBkeW5hbWljYWxseQogICAgICAgICAgICBvYmplY3QgblZhbCA9IENvbnZlcnQuQ2hhbmdlVHlwZSh2YWwsIHUpOy8vIG5WYWwgd2lsbCBiZSA1CiAgICAgICAgICAgIAogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiVHlwZSBpczogezB9LCBWYWx1ZSBpczogezF9IiwgblZhbC5HZXRUeXBlKCksIG5WYWwpOwoJfQp9