加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – operator’ – ‘不能应用于’decimal’和’Systems.Colle

发布时间:2020-12-16 01:47:43 所属栏目:百科 来源:网络整理
导读:我有这个错误,我想要解决. Visual Studio 2010将错误指定为: operator '-' cannot be applied to operands of type 'decimal' and 'Systems.Collections.Generic.IEnumerabledecimal 我的代码: // Step 5: Retrieve MPR amount and deduct form Gross Tax
我有这个错误,我想要解决.

Visual Studio 2010将错误指定为:

operator '-' cannot be applied to operands of type 'decimal' and 'Systems.Collections.Generic.IEnumerable<decimal>

我的代码:

// Step 5: Retrieve MPR amount and deduct form Gross Tax Dictionary Per-Employee

                //Query database
                var taxtable = taxTableService.GetAllTaxTables();

                var mprAmount = (from tt in taxtable select tt.U_MPR_amount).Distinct();

                Dictionary<int,decimal> paye = new Dictionary<int,decimal>();

                grossTaxDictionary.ToList().ForEach(x =>
                {
                    var totalPAYE = x.Value - mprAmount;

                    paye.Add(x.Key,totalPAYE);

                });

在我的数据库中,字段U_MPR_amount是小数,因此是x.Value.

错误显示在x.Value行 – mprAmount;

可能是什么问题呢?任何帮助赞赏.

解决方法

根据您的代码,mprAmount是一个列表,您不能从单个值中减去它.

如果您确定该列表只包含一个元素,那么您可以使用Single方法检索它:

var totalPAYE = x.Value - mprAmount.Single();

或者,更有可能:

var mprAmount = (from tt in taxtable select tt.U_MPR_amount).Single();

请注意,我已经更改了Distinct for Single.使用两者都没有任何意义.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读