at first I am a novice, I am learning is that only two months. (Sorry for my english, I hope u will understand.) Problem is: I am trying to create a small database with console application. I have student.csv where are all information about students. When I start application, all informations from this .csv will save into Lists. Like this:
List<Student> zoznam = new List<Student>(); List<string> inicZac = new List<string>(); List<string> ID = new List<string>(); List<string> Meno = new List<string>(); List<string> Priezvisko = new List<string>(); List<string> Adresa = new List<string>(); List<string> DatumNarodenia = new List<string>(); List<string> Heslo = new List<string>(); List<string> Login = new List<string>(); List<string> inicKon = new List<string>(); private int id; StreamReader reader = new StreamReader(File.OpenRead("student.csv")); public databazaStudentov() { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(';'); inicZac.Add(values[0]); ID.Add(values[1]); Meno.Add(values[2]); Priezvisko.Add(values[3]); Adresa.Add(values[4]); DatumNarodenia.Add(values[5]); Heslo.Add(values[6]); Login.Add(values[7]); inicKon.Add(values[8]); zoznam.Add(new Student(values[1], values[2], values[3], values[4], values[5], values[6], values[7])); } } It works good. But now I want secure an easy write into this .csv when I create a new student in a running application.This function is creating a new student:
public void addStudent(string meno, string priezvisko, string adresa, string datum) { string tempID = generujID(); //random gener ID string tempLogin = generujLogin(meno, priezvisko); //random gener Login string tempHeslo = generujHeslo(); //random gener password zoznam.Add(new Student(tempID, meno, priezvisko, adresa, datum, tempLogin, tempHeslo)); ID.Add(tempID); Meno.Add(meno); Priezvisko.Add(priezvisko); Adresa.Add(adresa); DatumNarodenia.Add(datum); Login.Add(tempLogin); Heslo.Add(tempHeslo); // I created a new student and now I want save him into the csv } and here is my .csv: https://i.sstatic.net/iyGCy.jpg
There are probably more ways how to fix it. I will be gratefull if someone show me How to save a new student on a new row or How to overwrite with Lists everything in my student.csv . Thanks for tips and sorry for my english.
string.Joinis the counterpart tostring.Split