Archive for the 'C#.NET' Category

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 [...]