1 回答
3
因为你在TEMP. " 74". 这两个值不相等,因为第二个TEMP2值"74"没有空格。
尝试使用Trim你的值来删除空格:
string temp = ids[i].Trim();
string temp2 = raditem.Value.ToString().Trim();
此外,请始终为class使用.Equals 重载String,因为您可以控制字符串比较的区域性。在这种情况下,这无关紧要,因为它们是数字,但如果您想与希望“A”等于“a”等的字母字符串进行比较,这可能很重要。
此外,如果您确定您的数组仅包含数字,我建议您在比较之前将这些值转换为数字。
// one way to validate is wrap this in a try-catch and handle input format error.
int temp = Convert.ToInt32(ids[i].Trim());
这样,如果您遇到没有数字的情况,您可以验证并向用户或您想要的任何内容投诉。
于 2018-08-27T11:42:28.947 回答
