I have a program that displays books from a list (Windows Forms). You can view the information about each one when selected and add a book as well. The format in the text file the program is reading from is:
(Type,Book Name,Year,Authors,Page Count)
Example:
Book,Summertime,2014,Pete Bear/Douglas Patrick,411
Since this book has more than one author, the delimiter is '/' and all authors are put into a list called Books, from the class Book. Since Books.Authors is a list rather than a string object, I have to use a method to put in the file output. How can I finish this method to associate it properly?
private void SaveFile()
{
// Declare file destination and empty
System.IO.File.WriteAllText("myBooks2.txt", string.Empty);
// Declare a StreamWriter variable.
StreamWriter outputFile;
// Create a file and get a StreamWriter object.
outputFile = File.AppendText("myBooks2.txt");
// For each book item existing, write the outputs
for (int i = 0; i < Books.Count; i++)
{
outputFile.WriteLine(Books[i].Type + "," + Books[i].Title + "," + Books[i].Year + "," + getElementsInList(Books[i].Authors) + "," + Books[i].Pages);
}
Method for author list
private string getElementsInList(List<string> aList)
{
string elements = "";
for (int i = 0; i < aList.Count; i++)
{
}
return elements;
}