我做错了什么?我试图让我的程序从csv文件读取数据,但我一直得到这个未处理的异常,是因为我如何编写txt文件?例外?
首先,我尝试将数据显示为控制台中的列表,但这也没有发生。我似乎无法在这里做到这一点,甚至可以从我的txt文件中读取它。
//My first program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PracticeProgram
{
public class Program
{
public static bool W2 { get; private set; }
public static void Main(string[] args)
{
List<Person> myContacts = new List<Person>();
// Loop to collect developers data
for (int i = 0; i < 4; i++)
{
Console.WriteLine("Welcome developer, enter your name to continue");
string name = Console.ReadLine();
Console.WriteLine("Hello, " + name);
Console.WriteLine("enter your address");
string address = Console.ReadLine();
Console.WriteLine(address);
Console.WriteLine("enter your monthly income");
double GrossMonthlyPay = 5000;
Console.WriteLine(GrossMonthlyPay);
Console.ReadLine();
Console.WriteLine("your tax deduction is set at 7%");
double taxes = (0.07);
Console.WriteLine(taxes);
Console.ReadLine();
Console.WriteLine("your monthly tax deduction is ");
Console.WriteLine(taxes = GrossMonthlyPay * taxes);
Console.ReadLine();
Console.WriteLine("Based on your monthly income your Annual gross pay is ");
double AnnualGrossPay = GrossMonthlyPay * 12;
Console.WriteLine(AnnualGrossPay);
Console.ReadLine();
Console.WriteLine("Your annual taxes are ");
double AnnualTaxes = AnnualGrossPay * 0.07;
Console.WriteLine(AnnualTaxes);
Console.ReadLine();
Console.WriteLine("Select 1 for W2, select 2 for 1099");
bool A = W2;
Console.WriteLine();
Console.ReadLine();
if (A)
{
Console.WriteLine("You employment type is W2");
}
else
{
Console.WriteLine("Your employment type is 1099");
}
Console.Write("\nPress any key to continue...");
Console.ReadLine();
myContacts.Add(new Person(name, address, GrossMonthlyPay, taxes, AnnualGrossPay, AnnualTaxes));
}
// Or you could read from CSV or any other source
foreach (string line in System.IO.File.ReadLines(@"C:\Users\Owner\Documents\Visual Studio 2015\Projects\new\data.txt"))
{
myContacts.Add(Person.ReadFromCSV(line));
}
// Serialize your informations at the end
foreach (Person contact in myContacts)
{
contact.SerializeToCSV(@"C:\Users\Owner\Documents\Visual Studio 2015\Projects\new\data.txt");
}
}
}
internal class Person
{
private string address;
private double grossMonthlyPay;
private string name;
private double taxes;
private double annualGrossPay;
private double annualTaxes;
public Person(string name, string address, double grossMonthlyPay, double taxes)
{
this.name = name;
this.address = address;
this.grossMonthlyPay = grossMonthlyPay;
this.taxes = taxes;
}
public Person(string name, string address, double grossMonthlyPay, double taxes, double annualGrossPay, double annualTaxes) : this(name, address, grossMonthlyPay, taxes)
{
this.annualGrossPay = annualGrossPay;
this.annualTaxes = annualTaxes;
}
public override string ToString()
{
return "Name=" + this.name + ",Address =" + this.address + " Monthly Pay=" + this.grossMonthlyPay + " Taxes=" + this.taxes.ToString();
}
internal static Person ReadFromCSV(string line)
{
throw new NotImplementedException();
}
internal void SerializeToCSV(string v)
{
throw new NotImplementedException();
}
}
}
答案 0 :(得分:1)
您的功能&#34; ReadFromCSV&#34;实施
throw new NotImplementedException();
尝试删除它或使用正确的代码实现