日期:2014-05-18  浏览次数:20544 次

运算符“==”无法应用于“decimal”和“string[]”类型的操作数
C# code
            if (this.getstring(base.Request.QueryString.Get("jg")) != "0")
            {
                string[] jg = this.getstring(base.Request.QueryString.Get("jg")).ToString().Split(new char[] { '-' });
                if (Convert.ToInt32(jg[1]) == 0)
                {
                    source = from c in source
                             where c.price == jg
                             select c;
                                   }
                else
                {
                    source = from c in source
                             where c.price == jg
                             select c;
}


------解决方案--------------------
提示的很明白了:c.price == jg中,==符号左右的类型不匹配,c.price是decimal型,而jg是数组,怎么能比较呢。

------解决方案--------------------
探讨

提示的很明白了:c.price == jg中,==符号左右的类型不匹配,c.price是decimal型,而jg是数组,怎么能比较呢。

------解决方案--------------------
强转其中的一个不就行了吗
------解决方案--------------------
如果是想用包含的话,
where jg.Contains(c.price)

不过看你意思,好像是jg得到的是一个范围?
source = from c in source
where c.price >= jg[0] && c.price <= jg[0]
select c;
------解决方案--------------------
where c.price >= jg[0] && c.price <= jg[1]

------解决方案--------------------
还是错了,类型还要转换
where c.price >= Convert.ToDecimal(jg[0]) && c.price <= Convert.ToDecimal (jg[1]

------解决方案--------------------
既然一个是数组,一个是数字,那么就可以用for比较了。
------解决方案--------------------
"这个人很高" == 170?
"这个人很矮" == 170?
------解决方案--------------------
把string decimal.parse 转换一下,, 要求string 只能是 数值