Instead of showing text line by line show the whole text

-3

Instead of displaying text line by line show the whole text. Visual Studio Community 2017.

Stream entrada = File.Open(varexe + "\Score.txt", FileMode.Open);
StreamReader leitor = new StreamReader(entrada);
string linha = leitor.ReadLine();
while (linha != null)
{
    MessageBox.Show(linha);
    linha = leitor.ReadLine();
}
leitor.Close();
entrada.Close();

    
asked by anonymous 31.10.2018 / 21:19

1 answer

1

Use the ReadToEnd() method and try using the using, when working with Stream and File , this will guarantee the Dispose() of the object as soon as it is no longer allocated

string texto = string.Empty;

using (Stream entrada = File.Open(varexe + "\Score.txt", FileMode.Open))
{
    StreamReader leitor = new StreamReader(entrada);
    texto = leitor.ReadToEnd();
}

MessageBox.Show(texto);
    
31.10.2018 / 21:26