错误 1 无法将带 [] 的索引应用于“StrigDs.SeqList<T>”类型的表达式 C:/Inetpub/wwwroot/StrigDs/StrigDs/Form5.cs 39 13 StrigDs
Error :
sqList[0] = key; //此句错误????????????
Program:
public class SeqList<T>
{
public SeqList<T> sqList;
public SeqList<T> GetLength()
{
return sqList.GetLength();
}
public int BinarySearch(SeqList<T> sqList, int key)
{
sqList[0] = key; //存放要查找的记录
int mid = 0;
int flag = -1;// 标志
int low = 1; //设置初始区间的下限值
int high = Convert.ToInt32(sqList.GetLength()); // 设置初始区间的上限值
//记录没有查找完
while (low <= high)
{
//middle
mid = (low + high) / 2;
if (sqList[0] == sqList[mid])
{
flag = mid;// search successful ,then save record to flag 's
break;
}
else if (sqList[0] < sqList[mid])
{ // left binary area
high = mid - 1;
}
else
{ // right binary area
low = mid + 1;
}
}
if (flag > 0)
{
Console.WriteLine("search is successful");
return flag;
}
else
{
Console.WriteLine("search is failed ");
return -1;
}
}
}