Advertisement
Fhernd

UsoIndexOutOfRangeException.cs

Jul 28th, 2014
4,401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Articulos.Cap04.Excepciones.Parte5
  4. {
  5.     public sealed class UsoIndexOutOfRangeException
  6.     {
  7.         public static void Main()
  8.         {
  9.             int[] arregloEnteros = new int[5];
  10.            
  11.             // Agrega 5 elementos al arreglo:
  12.             for (int i = 0; i < arregloEnteros.Length; ++i)
  13.             {
  14.                 arregloEnteros[i] = i + 1;
  15.             }
  16.            
  17.             try
  18.             {
  19.                 // Intengo de acceder a un elemento del
  20.                 // arreglo con un índice superior:
  21.                 Console.WriteLine (arregloEnteros[5].ToString());
  22.             }
  23.             catch (IndexOutOfRangeException ioore)
  24.             {
  25.                 Console.WriteLine ("Mensaje de error: `{0}`", ioore.Message);
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement