DRAG DROP
You are developing an application by using C#. The application will output the text string “First Line”
followed by the text string “Second Line”.
You need to ensure that an empty line separates the text strings.
Which four code segments should you use in sequence? (To answer, move the appropriate code
segments to the answer area and arrange them in the correct order.)
Answer: See the explanation
Explanation:
Box 1:First we create the variable.
Box 2:We create the first text line.
Box 3:We add a blank line.
The StringBuilder.AppendLine method appends the default line terminator to the end of the current
StringBuilder object.
Box 4:Finally we add the second line.
There is no empty line between “First Line” and “Second Line” in this solution. You need to append another line.
^^ what he said
2,3,5,7
Correct code should look like (tested in VS):
var sb = new StringBuilder();
sb.Append(“First Line”);
sb.AppendLine(); // double AppendLine() create empty line
sb.AppendLine();
sb.Append(“Second Line”);
I agree. There should be two sb.AppendLine() methods called.
You have to add also after: sb.Append(“Second Line”);
sb.AppendLine();