fork download
  1. using static System.Console;
  2. using System;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. int? x = null;
  7. int y = 10;
  8. string z = null; //só como exemplo, não faz sentido converter string p/ string
  9. try {
  10. WriteLine($"Convert.ToString(x) = {Convert.ToString(x)}");
  11. WriteLine($"Convert.ToString(y) = {Convert.ToString(y)}");
  12. WriteLine($"Convert.ToString(z) = {Convert.ToString(z)}");
  13. WriteLine($"x.ToString() = {x.ToString()}");
  14. WriteLine($"y.ToString() = {y.ToString()}");
  15. WriteLine($"z.ToString() = {z.ToString()}");
  16. } catch (Exception ex) {
  17. WriteLine("Falhou");
  18. WriteLine(ex);
  19. }
  20. }
  21. }
  22.  
  23. //https://pt.stackoverflow.com/q/121950/101
Success #stdin #stdout 0.02s 16808KB
stdin
Standard input is empty
stdout
Convert.ToString(x) = 
Convert.ToString(y) = 10
Convert.ToString(z) = 
x.ToString() = 
y.ToString() = 10
Falhou
System.NullReferenceException: Object reference not set to an instance of an object
  at Program.Main () [0x0008b] in <d8c047cd178c4cb7b7c3caf1b41673ce>:0