You are on page 1of 1

using System;

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab2
{
class Program
{
public static void WriteData(StreamWriter sw)
{
int isbn;
string bookName;
Console.WriteLine("ISBN:");
isbn = Convert.ToInt16(Console.ReadLine());
sw.WriteLine("ISBN:\n{0}", isbn);
Console.WriteLine("Book name:");
bookName = Console.ReadLine();
sw.WriteLine("Book name:\n{0}", bookName);
sw.Close();
}
public static void ReadData(StreamReader sr)
{
Console.WriteLine("\nList of the books:");
Console.WriteLine(sr.ReadToEnd());
sr.Close();
}
public static int SizeOfTheList(StreamReader sr2)
{
int count = 0;
string readData;
do
{
readData = sr2.ReadLine();
if (readData == "ISBN:")
count++;
} while (readData != null);
sr2.Close();
return count;
}
static void Main(string[] args)
{
StreamWriter sw = new StreamWriter(@"Books.txt",true);
WriteData(sw);

StreamReader sr = new StreamReader(@"Books.txt");


ReadData(sr);

StreamReader sr2 = new StreamReader(@"Books.txt");


Console.WriteLine("\nList contains {0} books.", SizeOfTheList(sr2));

}
}
}

You might also like