Last active
August 29, 2015 14:04
-
-
Save Fhernd/ceb9704792df92bc6498 to your computer and use it in GitHub Desktop.
Demostración del uso de la excepción NullReferenceException en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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