Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections;
  3.  
  4. namespace Articulos.Cap04.Excepciones.Parte5
  5. {
  6.     public sealed class UsoNullReferenceException
  7.     {
  8.         public static void Main()
  9.         {
  10.             // Define una variable de tipo ArrayList, sin embargo
  11.             // aún no ha sido inicializada. Sólo con null:
  12.             ArrayList al = null;
  13.            
  14.             try
  15.             {
  16.                 // Intento de agregar un elemento a la
  17.                 // variable ArrayList:
  18.                 al.Add ("Blog xCSw");
  19.             }
  20.             catch (NullReferenceException mre)
  21.             {
  22.                 Console.WriteLine ("Mensaje de error: `{0}`", mre.Message);
  23.             }
  24.         }
  25.     }
  26. }