Which four code segments should you use in sequence?

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.)

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.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


MarcoJacob

MarcoJacob

var sb = new StringBuilder();
sb.Append(“FirstLine”);

sb.AppendLine();
sb.Append(“SecondLine”);
Console.WriteLine(sb.ToString());

How they mean with “empty line between”, I don`t know. here you have a line break after “Firstline” but no empty line betwenn. You need a second AppendLine() for this

Andre Aranha

Andre Aranha

sb.Append DOES NOT write a line break. So we must call AppendLine to that.

The four code segments are:
1)var sb = new StringBuilder();
2)sb.Append(“FirstLine”);
3)sb.AppendLine();
4)sb.Append(“SecondLine”);

SairajGunner

SairajGunner

well, we might need two AppendLines to get the blank line done.