Выход за границы массива в блоке set{} - C#
Формулировка задачи:
Собственно сабж.
Почему он выходит за рамки, если идет заведомая проверка на это?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsolePanel
{
class Testing
{
private int[] mas;
public byte length;
public Testing(byte s)
{
mas = new int[s];
length = s;
}
public int this[int index]
{
get
{
if (index >= 0 & index <= length) return mas[index];
else return 0;
}
set
{
if(index>=0 & index<=length) mas[index] = value; // здесь выходит якобы за границы массива
}
}
}
class Program
{
static void Main(string[] args)
{
Testing t = new Testing(5);
for (sbyte i = 0; i < (t.length*2); i++ )
{
t[i] = i;
Console.Write("t[{1}] = {0}\n",t[i],i);
}
Console.ReadLine();
}
}
}Решение задачи: «Выход за границы массива в блоке set{}»
textual
Листинг программы
if(index>=0 & index<length) mas[index] = value;