Instead of displaying text line by line display the whole text

Asked

Viewed 89 times

-3

Instead of displaying text line by line display the entire 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();

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • Kind of confusing. But if I understood correctly, pq not concatenate into a variable in the loop and shows only at the end?

  • @Malystersnur managed to solve his problem?

1 answer

1

Use the method ReadToEnd() and try to use using, when working with Stream and File, this will ensure 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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.