이 개체의 목록을 가져 와서 텍스트 파일로 보내려고합니다. 텍스트 파일 형식은 다음과 같습니다.집합이 throw됩니다 StackOverflowException C#
name,IDnumber,department,value
이 꽤 몇 줄 그래서 나는이 읽기에 대한 코드입니다 . 그들을 파일을 읽고 쓰는 사용이 있습니다.
public void WriteFile(List<Employee> outList, string file) {
StreamWriter writeOut = new StreamWriter(file);
for (int i = 0; i < outList.Count; i++) {
writeOut.WriteLine(outList[i].name + '#' + outList[i].IDnum + '#' + outList[i].department + '#' + outList[i].position);
}
writeOut.close();
}
이
public List<Employee> ReadFile(string fileName) {
StreamReader fileIn = new StreamReader(fileName);
fileIn = File.OpenText(fileName);
List<Employee> list = new List<Employee>();
string[] test;
string name;
string ID;
string dep;
string post;
while (!fileIn.EndOfStream || !File.Exists(fileName)) {
string inString = fileIn.ReadLine();
test = inString.Split('#');
name = test[0];
ID = test[1];
dep = test[2];
post = test[3];
Employee newEmp = new Employee(name, ID, dep, post);
list.Add(newEmp);
}
fileIn.Close();
return list;
}
내 클래스에 대한 코드입니다. 세트에서 오류가 발생했습니다.
public class Employee {
public string name { get { return name; } set { name = value; } }
public string IDnum { get { return IDnum; } set { IDnum = value; } }
public string department { get { return department; } set { department = value; } }
public string position { get { return position; } set { position = value; } }
public Employee() {
name = string.Empty;
IDnum = string.Empty;
department = string.Empty;
position = string.Empty;
}
public Employee(string newName, string newID) {
name = newName;
IDnum = newID;
department = string.Empty;
position = string.Empty;
}
public Employee(string newName, string newID, string newDep, string
newPost) {
name = newName;
IDnum = newID;
department = newPost;
position = newDep;
}
}
필요에 따라 기능을 설정하기 위해 누락 된 형식의 서식이 있는지 확실하지 않습니다. 이 함수는 내가 파일 안팎을 호출하는 함수입니다. 나는 데이터를 가져오고있는 중일 가능성이 높습니다. 당신이 IDnum
에 대한 세터를 호출
IDnum = someValue;
같은 작업을 수행 할 때 스택
public string IDnum { get { return IDnum; } set { IDnum = value; } }
을 넘칠 때까지
<3 감사합니다. –