Hi,
I am working on a condition statement with a very long opening if statement and this requires me to keep scrolling right. How can I break onto a new line so my code is easier to read but without breaking the string?
e.g.
if (ThisUser.Company == "MyCompany" || ThisUser.Company == "MyCompany2" || ThisUser.Company == "MyCompany3" || ThisUser.Company == "MyCompany4" || ThisUser.Company == "MyCompany2")
{
Logo.ImageUrl = "../Images/Logo.png";
}
Thanks
M
Loading
VulpesPosted Aug 18, 2011, 5:58 AM
However, string literals (i.e. strings enclosed in quotes) shouldn't be broken unless you precede them with '@'. For example:
string str = @"ab
Sam HobbsPosted Aug 19, 2011, 1:36 AM
Max TenenbaumPosted Aug 18, 2011, 6:07 AM
Jiteendra SampathiraoPosted Aug 18, 2011, 6:05 AM
really no need worry about it...no error will comes...
if (a == 10 || b == 20 ||
c == 30)
{
Console.WriteLine("it works");
}
but if you are using are declaring string value then you have to use '+" operator like this..
string testing = "I am working on a condition statement with a very long opening"
+ "if statement and this requires me to keep scrolling right."
+ "How can I break onto a new line so my code is easier to"
+ "read but without breaking the string";
i hope u got my point.....
Satish BhatPosted Aug 18, 2011, 5:58 AM
But if you want to span a string into multiple lines you can either use " + " or string literal "@"
e.g.
string sqlString = "SELECT FIELD1, FIELD2 " +
"FROM TABLE_NAME " +
"WHERE FIELD3=100";
or
string sqlString = @"SELECT FIELD1, FIELD2
FROM TABLE_NAME
WHERE FIELD3=100";