I have a problem with adding line break in a string. I have tried using \"\\r\\n\", and Environment.NewLine also does not work.
FirmNames = \"\";
foreach (v
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;
FirmNames = "";
foreach (var item in FirmNameList)
{
if (FirmNames != "")
{
FirmNames += ", " + NewLine;
}
FirmNames += item;
}
string[] abcd = obj.show();
Response.Write(string.join("</br>", abcd));
This worked for me:
foreach (var item in FirmNameList){
if (FirmNames != "")
{
FirmNames += ",\r\n"
}
FirmNames += item;
}
Give this a try.
FirmNames = String.Join(", \n", FirmNameList);
Try using \n
when concatenating strings, as in this example:
var name = "Raihan";
var ID = "1234";
Console.WriteLine(name + "\n" + ID);
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;
}