所以我想要做的是读取一个文件,该文件有一个这样的数据段。到目前为止,程序从下拉菜单中打开文件,但我很难将它们保存到数组中。我希望能够在表单应用程序上打开文件(将文本文件的最后三行打印到文本框中)后单击下一步按钮,并将下面文本文件示例中的每个信息行打印到单独的文本框。这就是我遇到问题的地方。
将姓名和地址保存到 EmpNames 类中,然后将.split()
下面的数字保存到各自的 Employee 类中,以便设置为一系列计算,然后将结果打印到文本框中。
1
John MerryWeather
123 West Main Street
5.00 30
这样的数据段会有多个,但不超过10个。这是我目前所拥有的。
public partial class Form1 : Form
{
const int MAX = 10;
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog theDialog = new OpenFileDialog();
theDialog.Title = "Open Text File";
theDialog.Filter = "TXT files|*.txt";
theDialog.InitialDirectory = @"C:\";
if (theDialog.ShowDialog() == DialogResult.OK)
{
//Declarations:
// linesPerEmployee: Controls the number of lines to be read.
// currEmployeeLine: Controls where in the file you are reading.
Employee employee = new Employee();
NameAdd empNames = new NameAdd();
string filename = theDialog.FileName;
List<Employee> employeeList = new List<Employee>();
int linesPerEmployee = 4;
int currEmployeeLine = 0;
//parse line by line into instance of employee class
while (employeeList != null)
{
string[] filelines = File.ReadAllLines(filename);
if (filelines != null)
{
employee.EmpNum = int.Parse(filelines[0]);
empNames.Name =
}
}