I'm new to C# and writing this application that displays a message if the given name in the TextBox
is in the popular list file. My book gives very little help to fix this, my error is the inputfile of if(boy.Contains(boyinputFile))
same for the girl where it says something about:
cannot convert to string.
private void checkName_Click(object sender, EventArgs e)
{
string boy;
string girl;
girl = girlBox.Text;
boy = boyBox.Text;
StreamReader boyinputFile;
StreamReader girlinputFile;
boyinputFile = File.OpenText("BoyNames.txt");
girlinputFile = File.OpenText("GirlNames.txt");
while (!boyinputFile.EndOfStream)
{
if (boyBox.Text.Contains(boyinputFile))
{
MessageBox.Show("Yes, your name is popular!");
}
}
while (!girlinputFile.EndOfStream)
{
if (girl.Contains(girlinputFile))
{
MessageBox.Show("Yes, your name is popular!");
}
else
{
MessageBox.Show("Sorry, couldn't find your name.");
}
}
boyinputFile.Close();
girlinputFile.Close();
}