My suggestion would be to access your raw data from a collection that implements IEnumerable
to avoid having to hand code everything. I would use DateTime
to store the date rather than a magic string. The necessary conversion can be handled in the BillInfo
constructor.
public class BillInfo
{
public DateTime Date { get; set; }
public decimal Amount { get; set; }
private readonly CultureInfo cultureInfo = new("en-GB");
public BillInfo(decimal amount, string dateStr)
{
Amount = amount;
Date = DateTime.Parse($"1 {dateStr}", cultureInfo);
}
}
So the basic set up would be along these lines.
private static void Main()
{
List<(decimal amount, string dateStr)> RawData = new()
{
(91.93M, "August 2022"),
(66.00M, "August 2022"),
(91.82M, "September 2022"),
(66.00M, "September 2022"),
(91.82M, "October 2022"),
(66.00M, "October 2022")
};
List<BillInfo> billInfos = new();
foreach ((decimal amount, string dateStr) in RawData)
{
billInfos.Add(new BillInfo(amount, dateStr));
}
BillInfo[] billInfoArray = billInfos.ToArray();
var lastItemAdded = billInfos.Last();
Console.ReadLine();
}