I have a text file which holds input data for a guest at a hotel (Name, Nights staying, Corporate guest?). In the text file it will be displayed as
Ron,5,0 David,2 Ben,4,0
The format is Name,Number of Nights, Corporate Guest
. The 0
you can see in some lines indicates they are a corporate guest. If there's no 0 they are not a corporate guest.
This is the code I use to create the file and write to it:
// Creates file to open and to write to
StreamWriter X = new StreamWriter("Guests.txt");
// File will be written to : File Handling\bin\debug
for (int i = 0; i < 8; i++)
{
WriteLine();
Write("What is Guests name? : ");
name = ReadLine();
Write("How many nights are they staying? : ");
NightsStaying = int.Parse(ReadLine());
Write("Corporate Guest? (Y/N) : ");
CorporateGuest = Convert.ToChar(ReadLine());
if (CorporateGuest == 'Y')
{
X.WriteLine($"{name},{NightsStaying},{accBalance}");
}
else
{
X.WriteLine($"{name},{NightsStaying}");
}
}
X.Close();
Next, I created an object array, like this:
object[] arr = new object[10];
My problem now is I need to read in all this data and store in the array, so it can later be displayed on console. I also need to be able to know which records are regular Guests, and which are Corporate Guests.
Any help would be appreciated