You need to read the entire contents of a file named Message.txt into a single string variable. Which code segment should you use?

You need to read the entire contents of a file named Message.txt into a single string variable.
Which code segment should you use?




A. string result = null;StreamReader reader = new StreamReader(“Message.txt”);result =
    reader.Read().ToString();
B. string result = null;StreamReader reader = new StreamReader(“Message.txt”);result =
    reader.ReadToEnd();
C. string result = string.Empty;StreamReader reader = new StreamReader(“Message.txt”); while
    (!reader.EndOfStream) {
    result += reader.ToString();}
D. string result = null;StreamReader reader = new StreamReader(“Message.txt”);result =
    reader.ReadLine();


Answer: B

No comments:

Post a Comment