fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. int? x = 1;
  8. int? y = null;
  9.  
  10. Console.WriteLine(x.HasValue);
  11. Console.WriteLine(x.Value);
  12. Console.WriteLine(y.HasValue);
  13. Console.WriteLine(y.Value);
  14. }
  15. }
Runtime error #stdin #stdout #stderr 0.06s 26960KB
stdin
Standard input is empty
stdout
True
1
False
stderr
Unhandled Exception:
System.InvalidOperationException: Nullable object must have a value.
  at System.Nullable`1[System.Int32].get_Value () [0x00000] in <filename unknown>:0 
  at Test.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Nullable object must have a value.
  at System.Nullable`1[System.Int32].get_Value () [0x00000] in <filename unknown>:0 
  at Test.Main () [0x00000] in <filename unknown>:0