Adding Linebreaks in C#
Problem:
We want to insert linebreak character sequences into a string in C#.
Solution:
The platform safe way of doing this is by using the Environment.NewLine property.
msg = "An error occurred: " + Environment.NewLine + e.Message;
Composing a string with more than one line break can become really messy, so using string.Format might be a good idea.
msg = string.Format("{1} An error occurred!{0}Exception: {0}{2}",
Environment.NewLine, CurrentTime, e.ToString());
No comments yet.