kacalapy
kacalapy

Reputation: 10134

c# how to: define a long string with linebreaks?

is there a way to define a single long string with line breaks within the string definition code?

my string is somethign like this:

string sql = "SELECT 
                     a.bg_user_56 AS Project, 
                     a.bg_user_60 AS SubSystem, 
                     a.BG_USER_81 AS AssignedToUserName, 
                     a.bg_responsible AS AssignedTo,  
              FROM mytable"

Upvotes: 3

Views: 1380

Answers (5)

Sukesh Marla
Sukesh Marla

Reputation: 177

Use @ as

string s=@"Hello
           This is
           StackOverflow";

Upvotes: 0

Brian
Brian

Reputation: 38025

The @ sign is great for this, but for SQL, I like to define my SQL as a project resource. This makes it easy to read, update, and open in Query Analyzer (or the T-Sql editor of you choice) and execute.

Upvotes: 0

ChaosPandion
ChaosPandion

Reputation: 78262

Like this:

string sql = @"MyNiceCleanStoredProc @Param";

Upvotes: 0

user541686
user541686

Reputation: 210402

string sql = @"SELECT a.bg_user_56 AS Project,\r\na.bg_user_60 AS SubSystem,\r\na.BG_USER_81 AS AssignedToUserName,\r\na.bg_responsible AS AssignedTo,\r\nFROM mytable"

Upvotes: 0

Oded
Oded

Reputation: 498942

Use a verbatim string literal (that begins with a @):

string sql = @"SELECT 
                     a.bg_user_56 AS Project, 
                     a.bg_user_60 AS SubSystem, 
                     a.BG_USER_81 AS AssignedToUserName, 
                     a.bg_responsible AS AssignedTo,  
              FROM mytable"

Upvotes: 15

Related Questions