Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/ceb9704792df92bc6498 to your computer and use it in GitHub Desktop.
Save Fhernd/ceb9704792df92bc6498 to your computer and use it in GitHub Desktop.
Demostración del uso de la excepción NullReferenceException en C#.
using System;
using System.Collections;
namespace Articulos.Cap04.Excepciones.Parte5
{
public sealed class UsoNullReferenceException
{
public static void Main()
{
// Define una variable de tipo ArrayList, sin embargo
// aún no ha sido inicializada. Sólo con null:
ArrayList al = null;
try
{
// Intento de agregar un elemento a la
// variable ArrayList:
al.Add ("Blog xCSw");
}
catch (NullReferenceException mre)
{
Console.WriteLine ("Mensaje de error: `{0}`", mre.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment