Avertissement du compilateur (niveau 2) CS0251
Mise à jour : novembre 2007
Message d'erreur
Indexation d'un tableau avec un index négatif (les indices de tableau commencent toujours à zéro)
Indexing an array with a negative index (array indices always start at zero)
N'utilisez pas un nombre négatif pour l'indexation dans un tableau.
L'exemple suivant génère l'erreur 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);
}
}
}