当我在 C# 中使用以下代码时...
int totalValue = 0;
int total = 0;
totalValue = int.Parse(Session["price"].ToString()) * int.Parse(Session["day"].ToString());
// This line causes the error
totalValue += Session["IsChauffeurUsed"].ToString().Equals("Yes", StringComparer.CurrentCultureIgnoreCase) ? 80 : 0;
...我收到此错误:
无法使用实例引用访问成员“object.Equals(object, object)”;而是用类型名称来限定它。
该错误表明什么?
您使用了错误的参数类型。您可以使用Equals
作为实例级方法或类型级(静态)方法:
string.Equals(str1, str2, StringComparison comp);
str1.Equals(str2, StringComparison comp);
所以,在两者中,你都需要StringComparison
, not StringComparer
。还有你的:
totalValue += Session["IsChauffeurUsed"].ToString().Equals("Yes", StringComparison.CurrentCultureIgnoreCase) ? 80 : 0;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)