How to change the variable dynamically at runtime while mapping in a list in iteration?

Samuel 21 Reputation points
2022-09-05T05:40:12.86+00:00

Hi there everyone.
This is the first time I faced such situation.
I am mapping the data of a csv to an object of class where a list exists.
There are n columns names similar, only difference is the last character in their name.

For eg: FeeId1;Start1;End1;Amount1;FeeId2;Start2;End2;Amount2; and so on...

Here, I want to create a list which will have FeeId,Start,End,Amount, and I want to map the headers of csv in the object using iteration.
But as you can see below that while generating the object in iteration. at every iteration I want to change the header that gets mapped in that iteration.

List<PersonFee> personFee = new List<PersonFee>();

for iteration 1:
personFee.Add(new PersonFee{
FeeId = Convert.ToInt32(u.FeeId1),
Start= GetDateTime(u.Start1),
End = GetDateTime(u.End1),
Amount = Convert.ToInt32(u.Amount1),
PaymentSchedule = (PersonFeePaymentScheduleEnum)(Convert.ToInt32(u.PaymentSchedule1))
}

for iteration 2:
personFee.Add(new PersonFee{
FeeId = Convert.ToInt32(u.FeeId2),
Start= GetDateTime(u.Start2),
End = GetDateTime(u.End2),
Amount = Convert.ToInt32(u.Amount2),
PaymentSchedule = Convert.ToInt32(u.PaymentSchedule2)
}
and so on with more iterations.
Now the problem is that how can we change the name of header in each iteration at the RUNTIME?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,156 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,251 questions
{count} votes