adding line break
The correct answer is to use Environment.NewLine
, as you've noted. It is environment specific and provides clarity over "\r\n" (but in reality makes no difference).
foreach (var item in FirmNameList)
{
if (FirmNames != "")
{
FirmNames += ", " + Environment.NewLine;
}
FirmNames += item;
}
Give this a try.
FirmNames = String.Join(", \n", FirmNameList);
C# 6+
In addition, since c#6 you can also use a static using statement for System.Environment.
So instead of Environment.NewLine, you can just write NewLine.
Concise and much easier on the eye, particularly when there are multiple instances ...
using static System.Environment;
...
foreach (var item in FirmNameList)
{
if (FirmNames != "")
{
FirmNames += ", " + NewLine;
}
FirmNames += item;
}