Created
July 29, 2014 03:37
-
-
Save Fhernd/b51e8018c38ec0c8a38f to your computer and use it in GitHub Desktop.
Demostración del uso de la excepción IndexOutOfRangeException 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; | |
namespace Articulos.Cap04.Excepciones.Parte5 | |
{ | |
public sealed class UsoIndexOutOfRangeException | |
{ | |
public static void Main() | |
{ | |
int[] arregloEnteros = new int[5]; | |
// Agrega 5 elementos al arreglo: | |
for (int i = 0; i < arregloEnteros.Length; ++i) | |
{ | |
arregloEnteros[i] = i + 1; | |
} | |
try | |
{ | |
// Intengo de acceder a un elemento del | |
// arreglo con un índice superior: | |
Console.WriteLine (arregloEnteros[5].ToString()); | |
} | |
catch (IndexOutOfRangeException ioore) | |
{ | |
Console.WriteLine ("Mensaje de error: `{0}`", ioore.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment