fork(12) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. Type t = typeof(int?); //will get this dynamically
  8. Type u = Nullable.GetUnderlyingType(t);
  9. object val = 5; //will get this dynamically
  10. object nVal = Convert.ChangeType(val, u);// nVal will be 5
  11.  
  12. Console.WriteLine("Type is: {0}, Value is: {1}", nVal.GetType(), nVal);
  13. }
  14. }
Success #stdin #stdout 0.04s 33944KB
stdin
Standard input is empty
stdout
Type is: System.Int32, Value is: 5