I am working on trying to make a trivia game in c#. I want to load in a simple .txt file for the questions and the answers. But I can't seem to get the questions to display to the console. Here is the code for loading in the .txt file
static void LoadData(string filename)
{
try
{
using(StringReader reader = new StringReader(filename))
{
string line;
while((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch(Exception e)
{
Console.WriteLine("File could not be read");
Console.WriteLine(e.Message);
}
}
Here is the code where I am trying to display the questions to the console. Right now all that happens is the location of the text file gets displayed but nothing else.
static void Main(string[] args)
{
string filename = @"C:\Trivia\questions.txt";
LoadData(filename);
}
The text file looks like this
What is another name for SuperMan?
What is Superman's only weakness?
What is the name of Batman's secret identity?
Batman protects what city?
How did Spiderman get his superpowers?
This superheros tools include a bullet-proof braclets and a magic lasso.Who is she?
Which superhero has an indestructible sheild?
Which superhero cannot transformback into human form?
What villan got his distinctive appearance form toxic chemicals?
What is the name of the archnemesis of the Fantastic Four?
I am really unsure on what I am doing wrong. Any suggestions would be appreciated.
Thanks