Kin*_*mau 3 c# visual-studio-2010
我有这个错误,我想要解决.
Visual Studio 2010将错误指定为:
operator '-' cannot be applied to operands of type 'decimal' and 'Systems.Collections.Generic.IEnumerable<decimal>
Run Code Online (Sandbox Code Playgroud)
我的代码:
// 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);
});
Run Code Online (Sandbox Code Playgroud)
在我的数据库中,字段U_MPR_amount是小数,因此是x.Value.
错误显示在该行上 x.Value - mprAmount;
可能是什么问题呢?任何帮助赞赏.
根据您的代码,mprAmount是一个列表,您不能从单个值中减去它.
如果您确定该列表只包含一个元素,那么您可以使用以下Single方法检索它:
var totalPAYE = x.Value - mprAmount.Single();
Run Code Online (Sandbox Code Playgroud)
或者,更有可能:
var mprAmount = (from tt in taxtable select tt.U_MPR_amount).Single();
Run Code Online (Sandbox Code Playgroud)
请注意,我已经改变Distinct了Single.使用两者都没有任何意义.
| 归档时间: |
|
| 查看次数: |
2425 次 |
| 最近记录: |