【发布时间】:2019-08-14 09:43:49
【问题描述】:
必须添加销售代表姓名、金额、计算佣金,并从数组中删除销售代表和销售。
我正在努力使用 searchSeller 方法,并且在超过 24 小时内没有取得任何进展。
static string SearchSeller(int[] sellerSales, string[] sellerNames, int sellerCount,
ref string salesRep)
{
int index = 0;
bool found = false;
while (!found && index < sellerCount)
{
if (salesRep = sellerNames[index])
found = true;
else
index++;
}
if (!found)
index = -1;
return sellerNames[index];
}
问题似乎出在某个地方:
if (salesRep = sellerNames[index])
错误提示:
无法将字符串转换为布尔值。
【问题讨论】:
-
欢迎来到 Stack Overflow。这是一个很好的第一个问题。 :)
-
顺便说一句,您应该检查
Array.FindIndex()或者 Linq 的 Enumerable.First()、Enumerable.Single() 和 Enumerable.Contains 。 Try it online