Advertisement
Fhernd

UsoNullReferenceException.cs

Jul 28th, 2014
4,417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement