Click here to Skip to main content
15,172,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
MonthlyPayments = new List<MonthlyPayment>();
            MonthlyPayment payment = new MonthlyPayment()
            {
                Luna = 0,
                SoldInitial = 0,
                PlataLunara = 0,
                DobandaLunara = 0,
                Principal = 0,
                AsigurareLunara = 0,
                ComisionLunar = ComisionAnaliza,
                TotalLunar = ComisionAnaliza,
                SoldCredit = ValoareCredit,
            };
            PaymentsDataGrid.Items.Add(payment);
            for (int i = 2; i <= n; i++)
            {

                
            }
            
            paymentViewSource = new CollectionViewSource();
            this.DataContext = paymentViewSource;

        }

        public MonthlyPayment InitializeMyObject(int i, MonthlyPayment lastMonth)
        {

            MonthlyPayment x = new MonthlyPayment();
            x.Luna = i;
            x.SoldInitial = Math.Round(lastMonth.SoldCredit, 2);
            double c = Comision / 12;
            double d = Dobanda / 12;
            x.DobandaLunara = Math.Round(d * lastMonth.SoldCredit, 2);
            double v = 1 + d;
            x.PlataLunara = Math.Round((ValoareCredit * d) / (1 - Math.Pow((v), -12)), 2);
            x.Principal = Math.Round(x.PlataLunara - x.DobandaLunara, 2);
            x.AsigurareLunara = Math.Round(Asigurare * lastMonth.SoldCredit, 2);
            x.ComisionLunar = Math.Round(c * ValoareCredit, 2);
            x.TotalLunar = Math.Round(x.ComisionLunar + x.AsigurareLunara + x.PlataLunara, 2);
            x.SoldCredit = Math.Round(lastMonth.SoldCredit - x.Principal, 2);

            return x;

        }

What do I need to add in the for(i=1;i<=n;i++) to calculate the following n rates?

What I have tried:

C#
for (int i = 2; i <= n; i++)
            {

                PaymentsDataGrid.Items.Add(InitializeMyObject(i,PaymentsDataGrid.Items[ i -1]));

            }

But I have error 'Cannot convert from 'object'to CreditSimulation.MonthlyPayment'.
Posted
Updated 16-May-21 11:14am

1 solution

You have the cast "item" of Items, which is an object collection.

...PaymentsDataGrid.Items[i-1] as MonthlyPayment.


Everything is an object; but not every object can pass for a MonthlyPayment.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900