How we can add a new line in c# [duplicate]
Asked Answered
M

4

12

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"

Motta answered 16/6, 2017 at 10:10 Comment(1)
Environment.NewLineImpetus
S
22
"my name is " + "\n" + "yazdan" 

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

Schuller answered 16/6, 2017 at 10:13 Comment(0)
M
4

You could try this:

"my name is " + Environment.NewLine + "yazdan"
Mensal answered 16/6, 2017 at 10:12 Comment(0)
Z
2
MessageBox.Show("my name is " + Environment.NewLine + "yazdan", MessageBoxButton.OK, MessageBoxIcon.Information);
Zoller answered 16/6, 2017 at 10:15 Comment(0)
F
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

Freelance answered 16/6, 2017 at 10:22 Comment(1)
i'm using windowMotta

© 2022 - 2024 — McMap. All rights reserved.