读书人

运算符“==”无法应用于“decimal”和

发布时间: 2012-04-15 18:39:21 作者: rapoo

运算符“==”无法应用于“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 只能是 数值

读书人网 >asp.net

热点推荐