I´m currently trying to improve my c# skills and want to make a check-in system for workers. I want to save the timestamps in a text file and add every new stamp in the same personal .txt file.
My problem is not making it work, my problem is when I write out my list the line System.Collections.Generic.List
1[System.String]` is added for every text I add. Please Help me solve this problem.
I don´t really know how to get rid of the System.Collections.Generic.List
1[System.String]` part
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Provar_på_IO_File_system
{
class Program
{
static void Main(string[] args)
{
string workerName = "Albert Einstien";
string date = "2019-10-17";
string time = "14.29";
if (File.Exists(workerName + ".txt"))
{
string line;
StreamReader sr = new StreamReader(workerName + ".txt");
List<string> readLines = new List<string>();
line = sr.ReadLine();
while (line != null)
{
readLines.Add(line);
line = sr.ReadLine();
}
sr.Close();
using (StreamWriter sw = File.AppendText(workerName + ".txt"))
{
sw.WriteLine(readLines);
sw.WriteLine("HELLLLLLLLLOOOOOOOOOOOOOOOOOOOOOOOO");
sw.Close();
}
}
else
{
FileStream fs = new FileStream(workerName + ".txt", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(date + "\t" + time + "\t" + workerName);
sw.Close();
fs.Close();
}
}
}
}
So the result I'm planning to get from this is to see if just that worker has a text file. If it has none it will create a personal file for that person and add the timestamps for him. Otherwise, if the file already, exists (he have already check-in at least once) the program will read the .txt file, save every line into a list and after that write everything that stod in the file when the system opened it but also add the new timestamp.
Everything works as I like but it doesn't only add the timestamp, the program adds the line System.Collections.Generic.List
1[System.String]" and then the timestamps.