我正在调试Silverlight应用程序,并遇到数组索引超出范围的问题。我对DataTable.Select语句的语法不太熟悉,并且应用程序的开发人员在接下来的10天内不在城里。这条线
searchParamsTable.Select(string.Format(“TABLE = {0} AND FIELD ='{1}'”,tableNumbers [i],fieldName [i]))[0] [“VALUE”] = wildcardedSearchString;
从下面的代码中可以看出“索引超出界限,这发生在”i“的第二次迭代中,当i = 1时。我不确定[0] [”VALUE“]代表什么在这种情况下。如果有人能够解释这个字符串中的内容,我将非常感激!
if (i < 2 || country != -1)
{
if (!string.IsNullOrEmpty(wildcardedSearchString))
{
searchParamsTable.Select(string.Format("TABLE = {0} AND FIELD = '{1}'", tableNumbers[i], fieldName[i]))[0]["VALUE"] = wildcardedSearchString;
MarkRequiredParametersForSearch(searchParamsTable);
returnList = GetSearchResults(contactType, session, searchParamsTable, returnList,
(int)searchParamsTable.Select(string.Format("TABLE = {0} AND FIELD = '{1}'", tableNumbers[i], fieldName[i]))[0]["FIELDNO"]);
// Filter by authority type if necessary.
if (authorityType != AuthorityType.Unknown)
{
var results = from EntitySearchResult result in returnList
where result.SubType == (int)authorityType
select result;
if (results != null)
{
returnList = results.ToList();
}
}
}
}
答案 0 :(得分:2)
DataTable.Search()
会返回DataRow[]
,因此[0]["VALUE"]
会从Search
返回的第一行中获取“VALUE”列的值。
可以重写为:
DataRow[] foundRows searchParamsTable.Select(string.Format("TABLE = {0} AND FIELD = '{1}'", tableNumbers[i], fieldName[i]));
DataRow firstRow = foundRows[0];
firstRow["VALUE"] = wildcardedSearchString;
从您的代码示例中看起来您有几个索引超出范围异常的地方:
Search
返回零行。