8

How we can write output on second line in c# ??
How we can write the given code into two lines

MessageBox.Show("my name is " + LineBreak, "yazdan" ,
                 MessageBoxButton.OK, MessageBoxIcon.Information);

How we can start a new line after "my name is " and before "yazdan"

Yazdan Haider
  • 975
  • 1
  • 7
  • 10

4 Answers4

17
"my name is " + "\n" + "yazdan" 

you can use either "\n" or Environment.NewLine

Vicky S
  • 762
  • 4
  • 16
2

You could try this:

"my name is " + Environment.NewLine + "yazdan"
Christos
  • 53,228
  • 8
  • 76
  • 108
2
MessageBox.Show("my name is " + Environment.NewLine + "yazdan", MessageBoxButton.OK, MessageBoxIcon.Information);
someguy76
  • 415
  • 4
  • 22
2

Depends on your environment, in Unix it is just "\n", however in Windows environments you need "\r\n". These are both written as strings.

\r = Carriage return \n = Line feed

This is the equivalent to vbCrLf in VB.NET

ataraxia
  • 995
  • 13
  • 31