Good morning
I would like to enquire as to how to read a list from a text file and to save the info into a list(array) with c#.
Its a little exercise where I wrote the info to a text file and now I want to read the info and save it into a different array.
string name;
string selection;
FileStream fs = new FileStream("C:/Documents and Settings/Arian/Desktop/Perl (PERLC-09)/bookExamples/unitThree/menuLunch.txt", FileMode.Create, FileAccess.ReadWrite);
BufferedStream bs = new BufferedStream(fs);
fs.Close();
StreamWriter sw = new StreamWriter("C:/Documents and Settings/Arian/Desktop/Perl (PERLC-09)/bookExamples/unitThree/menuLunch.txt");
Console.WriteLine("writing the menu");
string[]menu = new string[]{"burger", "steak", "sandwich", "apple", "soup", "pasta", "pizza"};
for (int i = 0; i < menu.Length; i++)
{
sw.WriteLine(menu[i]);
}
sw.Close();
Console.WriteLine("Thanks for creating the menu, could you please tell me your name? ");
name = Console.ReadLine();
Console.WriteLine("hallo " + name + " Please make your selection from the menu");
FileStream fsream = new FileStream("C:/Documents and Settings/Arian/Desktop/Perl (PERLC-09)/bookExamples/unitThree/menuLunch.txt", FileMode.Open, FileAccess.Read);
BufferedStream bstream = new BufferedStream(fsream);
fsream.Close();
StreamReader sr = new StreamReader("C:/Documents and Settings/Arian/Desktop/Perl (PERLC-09)/bookExamples/unitThree/menuLunch.txt");
while (!sr.EndOfStream)
{
Console.WriteLine(sr.ReadLine());
}
selection = Console.ReadLine();
regards