Advertencia del compilador (nivel 2) CS0251

Actualización: noviembre 2007

Mensaje de error

Indizando una matriz con un índice negativo (los índices de matriz siempre comienzan por cero)
Indexing an array with a negative index (array indices always start at zero)

No utilice un número negativo para indizar una matriz.

El código siguiente genera el error CS0251:

// CS0251.cs
// compile with: /W:2
class MyClass
{
   public static void Main()
   {
      int[] myarray = new int[] {1,2,3};   
      try
      {
         myarray[-1]++;   // CS0251
         // try the following line instead
         // myarray[1]++;
      }
      catch (System.IndexOutOfRangeException e)
      {
         System.Console.WriteLine("{0}", e);
      }
   }
}