c#中应用一个冒泡排序法,总是提示Index was out of range.Must be non-negative
c#中应用一个冒泡排序法,总是提示Index was out of range.Must be non-negative and less than the size
程序:
IList img_S = new List();
IList Tem = new List();
for (int i = 0; i < c; i++)
{
for (int j = 0; j < c - i-1; j++)
{
if (img_S[j].Similarity > img_S[j + 1].Similarity)
{
Tem[0] = img_S[j];
img_S[j] = img_S[j + 1];
img_S[j + 1] = Tem[0];
}
}
}
c是 img_S的总个数,Tem是我建立的中间数列.出现的错误提示指示在第一个 Tem[0] 处