[Solved] List or dictionary in C#


I would use a list of tuples like this:

double TotalDebts = 30000;
list<Tuple<int, double>> AllDebits = new list<Tuple<int, double>>();
for (int i = 0; i < 250; i++)
{
    if (TotalDebts > 0)
    {
        double DebtsLessIncome = Convert.ToDouble(TotalDebts - 1000);
        double InterestCharged = Convert.ToDouble((DebtsLessIncome * 5) / 100);
        double InterestDebt = Convert.ToDouble(DebtsLessIncome + InterestCharged);
        double InterestDebtMLE = Convert.ToDouble(InterestDebt + 500);
        TotalDebts = Convert.ToDouble(InterestDebtMLE);
        AllDebits.Add(new Tuple<int,double>(i, TotalDebts));
    }
}

It really depends on what you’ll be using this for. If the data is really just to display in a list then this is fine. However, if the index is to be used for something else (id perhaps?) then a Dictionary (as per fubo’s answer) would be much better, as the index has meaning and needs to be unique (Dictionaries don’t allow duplicate keys).

0

solved List or dictionary in C#