컴파일러 경고(수준 2) CS0251

오류 메시지

음수 인덱스를 사용하여 배열을 인덱싱했습니다. 배열 인덱스는 항상 0부터 시작합니다.
Indexing an array with a negative index (array indices always start at zero)

배열 인덱스에 음수를 사용할 수 없습니다.

다음 샘플에서는 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);
      }
   }
}