What is the correct syntax in c# to create a line break in the middle of a mysql string?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Multiline String Literal in C#
我可能没有向谷歌提出正确的问题来找到我的答案。我只想保持代码整洁,而不想在一行上有一个很长的字符串。我想移动到下一行而不打断字符串。
1 | 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 2 3 4 5 6 7 8 | 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 2 3 4 5 6 | 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 2 3 4 5 6 7 8 | 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 2 3 | 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 2 | cmd.CommandText ="text text" + "text text"; |
这叫做串联:
1 2 3 | 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 2 | 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)"; |