php - How to begin "block of string" formatting in C#? -


i have write queries in c# code , had question formatting. see below:

    string sql = "select * ";     sql += "from hyt_user_vehicle_group_assoc ";     sql += "inner join hyt_vehicle_group on hyt_vehicle_group.vehicle_group_no = hyt_user_vehicle_group_assoc.vehicle_group_no "; 

coming php background, how have written in php:

$sql = "select *     hyt_user_vehicle_group_assoc     inner join hyt_vehicle_group on hyt_vehicle_group.vehicle_group_no = hyt_user_vehicle_group_assoc.vehicle_group_no";  

notice how don't have write sql += each new line in string? there wayto tell c# i'm going begin "block of string", such don't have type sql +=?

yup - use verbatim string literal putting @ before leading ":

string sql = @"select *     hyt_user_vehicle_group_assoc     inner join hyt_vehicle_group     on hyt_vehicle_group.vehicle_group_no = hyt_user_vehicle_group_assoc.vehicle_group_no"; 

note removes escaping backslash - 1 of times it's useful regular expressions , windows file paths. include double-quote in verbatim string literal, double it:

string text = "jon says, ""verbatim string literals."" , that's all."; 

for particularly large blocks of code-as-text, i'd stick them in separate embedded resource, mind - or use orm didn't need sql majority of data access :)

for more on strings, string literals (regular , verbatim), escape sequences etc, see article on topic.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -