I am trying to calculate the total for a list in my C# program, I have gotten help from several people in my class and we can't seem to find the problem, my code is,
int totalB = 0;
Cards.ForEach(delegate(ConsoleApplication1.Program.CreditCard Balance)
{
totalB= totalB + Balance;
});
The error is this Error 1 Operator '+' cannot be applied to operands of type 'int' and 'ConsoleApplication1.Program.CreditCard'
Any help for this would be much appreciated as I have no idea and neither do the people that tried to help me with this issue
As far as getting sum of list is concerned. it is as simple as (assuming Cards is a list)
Your Error:
you are trying to add an int with ConsoleApplication1.Program.CreditCard (what is this) which is obviously not a type that can be added to int. Hence the error you are getting.