I am reading data from CVS file into C# list object . I can only read string values. When I try to read a numerical value (double in this case) I get input string was not in correct format exception. Anyone can show me how to overcome this? Here is the code:
class :
public class Loan
{
string applicationDT;
string employeeID;
string employeeName;
double amount;
string lonType;
public void printLoan()
{
Console.WriteLine($" employeeName {employeeName} employee Id {employeeID}" +
$"applicationDate {applicationDT} \namount {amount} loanType {lonType}");
}
public static Loan fromCVS(string csvLine)
{
string []values = csvLine.Split(',');
Loan loanRecord = new Loan();
loanRecord.employeeName = (values[3]);
loanRecord.employeeID = (values[4]);
loanRecord.applicationDT = (values[5]);
loanRecord.amount = Convert.ToDouble(values[6]);
loanRecord.lonType = (values[7]);
return loanRecord;
}
}
Main:
static void Main()
{
List<Loan> loans = File.ReadAllLines(@"C:\Users\0300Test.csv")
.Skip(1)
.Select(v => Loan.fromCVS(v))
.ToList();
foreach(Loan aLoan in loans)
{
aLoan.printLoan();
}
}
CSV file :
"APPROVAL_OFFICER_NAME","APPROVAL_OFFICER_ID","RELATIONSHIP_MANAGER_NAME","EMPLOYEE_NAME","EMPLOYEE_ID","APPLICATION_DATE_TIME","AMOUNT","TYPE_OF_LOAN"
"SAMPLNAME","988803","SAMPLNAME","SAMPLNAME","776667","1/22/2019 11:05:43 AM","321146.00","Top Up With Settlement"
"SAMPLNAME","988803","SAMPLNAME","SAMPLNAME","776667","1/22/2019 9:34:13 AM","90230.00","Top Up With Settlement"
"SAMPLNAME","988803","SAMPLNAME","SAMPLNAME","776667","1/22/2019 12:00:22 AM","5230.00","Top Up without Settlement"