What is the correct syntax in C # to create a line break in the middle of a mysql line?

Possible duplicate:
Multiline string literal in C #

I probably don't ask the right Google questions to find my answer. I just want my code to be neat, without actually having a long line on one line. I want to go to the next line without breaking the line.

cmd.CommandText = "UPDATE players SET firstname = CASE id WHEN 1 THEN 'Jamie' WHEN 2 THEN 'Steve' WHEN 3 THEN 'Paula' END WHERE id IN (1,2,3)"; 

For example, I would like to split this into two lines without affecting the line. All help would be appreciated.

+6
source share
7 answers

I suspect you want to use @ for shorthand lines; The advantage of shorthand lines is that escape sequences are not processed and that they can span multiple lines.

 cmd.CommandText = @"UPDATE players SET firstname = CASE id WHEN 1 THEN 'Jamie' WHEN 2 THEN 'Steve' WHEN 3 THEN 'Paula' END WHERE id IN (1,2,3)"; 
+6
source

You can use @ in fronf of your string. This is called Verbatim String Literal.

 cmd.CommandText = @" UPDATE players SET firstname = CASE id WHEN 1 THEN 'Jamie' WHEN 2 THEN 'Steve' WHEN 3 THEN 'Paula' END WHERE id IN (1,2,3)"; 
+3
source

Use the @ character before the line. It will tell the compiler that the string is multi-line.

 cmd.CommandText = @"UPDATE players SET firstname = CASE id WHEN 1 THEN 'Jamie' WHEN 2 THEN 'Steve' WHEN 3 THEN 'Paula' END WHERE id IN (1,2,3)"; 
+3
source

like this

 cmd.CommandText = "UPDATE players SET firstname =" + " CASE id WHEN 1 THEN 'Jamie' WHEN 2 THEN 'Steve' WHEN 3" + " THEN 'Paula' END WHERE id IN (1,2,3)"; 
+1
source

Simple string concatenation as follows:

 cmd.CommandText = "UPDATE players SET firstname = CASE id WHEN 1 " cmd.CommandText +="THEN 'Jamie' WHEN 2 THEN 'Steve' WHEN 3 THEN 'Paula' END WHERE id IN (1,2,3)"; 
0
source

It is called concatenation:

 cmd.CommandText = "UPDATE players SET firstname" + " = CASE id WHEN 1 THEN 'Jamie' WHEN 2 THEN 'Steve'" + " WHEN 3 THEN 'Paula' END WHERE id IN (1,2,3)"; 
0
source

Like this?

 cmd.CommandText = "text text" + "text text"; 
0
source

Source: https://habr.com/ru/post/926531/


All Articles