is it possible to make this into a list and then make a code where I can delete what's inside the list per line (text file) and then searching the contents of the list
class data
{
public void addData(string user_name, string user_email, string user_gender, string user_contact)
{
using (StreamWriter writer = new StreamWriter("data.txt", true))
{
writer.WriteLine(user_name " | " user_email " | " user_gender " | " user_contact);
}
}
}
CodePudding user response:
It is possible! And Microsoft write some really nice documentation for you to learn about it right here. Here's a simple little program to read the file into a list.
const string file = "{insert your path here}/data.txt";
var stringList = File.ReadLines(file).ToList();
foreach (var line in stringList)
{
Console.WriteLine(line);
}
There's a nice example on the documentation I've linked that shows you how to lookup things on that list so I'll leave the next part for you to work out