I have this error that I am tying to solve.
Visual Studio 2010 gives the error as:
operator '-' cannot be applied to operands of type 'decimal' and 'Systems.Collections.Generic.IEnumerable<decimal>
My Code:
// 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);
});
In my database, the field U_MPR_amount is a decimal and so is x.Value.
Error shows up on the line x.Value - mprAmount;
What could be the problem? Any help appreciated.
According to your code,
mprAmountis a list, you cannot subtract it from a single value.If you are certain that the list contains just a single element then you can retrieve it using the
Singlemethod:Or, more likely:
Notice that I’ve changed
DistinctforSingle. Using both makes no real sense.