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);
}
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIEFydGljdWxvcy5DYXAwNC5FeGNlcGNpb25lcy5QYXJ0ZTUKewogICAgcHVibGljIHNlYWxlZCBjbGFzcyBVc29JbmRleE91dE9mUmFuZ2VFeGNlcHRpb24KICAgIHsKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICBpbnRbXSBhcnJlZ2xvRW50ZXJvcyA9IG5ldyBpbnRbNV07CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBBZ3JlZ2EgNSBlbGVtZW50b3MgYWwgYXJyZWdsbzoKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBhcnJlZ2xvRW50ZXJvcy5MZW5ndGg7ICsraSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYXJyZWdsb0VudGVyb3NbaV0gPSBpICsgMTsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgdHJ5CiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIC8vIEludGVuZ28gZGUgYWNjZWRlciBhIHVuIGVsZW1lbnRvIGRlbCAKICAgICAgICAgICAgICAgIC8vIGFycmVnbG8gY29uIHVuIMOtbmRpY2Ugc3VwZXJpb3I6CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoYXJyZWdsb0VudGVyb3NbNV0uVG9TdHJpbmcoKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY2F0Y2ggKEluZGV4T3V0T2ZSYW5nZUV4Y2VwdGlvbiBpb29yZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJNZW5zYWplIGRlIGVycm9yOiBgezB9YCIsIGlvb3JlLk1lc3NhZ2UpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9