Multiline string literal in C#

后端 未结 13 1498
梦谈多话
梦谈多话 2020-11-22 11:15

Is there an easy way to create a multiline string literal in C#?

Here\'s what I have now:

string query = \"SELECT foo, bar\"
+ \" FROM table\"
+ \" W         


        
13条回答
  •  忘了有多久
    2020-11-22 11:30

    I haven't seen this, so I will post it here (if you are interested in passing a string you can do this as well.) The idea is that you can break the string up on multiple lines and add your own content (also on multiple lines) in any way you wish. Here "tableName" can be passed into the string.

        private string createTableQuery = "";
    
        void createTable(string tableName)
        {
    
             createTableQuery = @"CREATE TABLE IF NOT EXISTS
                    ["+ tableName  + @"] (
                   [ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
                   [Key] NVARCHAR(2048)  NULL, 
                   [Value] VARCHAR(2048)  NULL
                                    )";
        }
    

提交回复
热议问题