c# code cleanup to break statement in multiple line
本问题已经有最佳答案,请猛点这里访问。
我有这个C代码来创建数据库。这是工作代码。但它因为一条线而难看。我想把它分成多行。如果我只是按Enter键输入换行符,它会给出语法错误。如何用更清洁的方式将其烧掉:
1 | string createDataBase = $"CREATE DATABASE {dataBaseName} ON PRIMARY (NAME = {dataBaseName}_Primary, FILENAME = '{primaryPath}'), FILEGROUP {dataBaseName}_FileStreamGroup CONTAINS FILESTREAM(NAME = {dataBaseName}_Filestream, FILENAME = '{filePath}')"; |
请告诉我怎么打破它?
只需使用
1 2 3 4 5 6 | string createDataBase = $@"CREATE DATABASE {dataBaseName} ON PRIMARY (NAME = {dataBaseName}_Primary, FILENAME = '{primaryPath}'), FILEGROUP {dataBaseName}_FileStreamGroup CONTAINS FILESTREAM(NAME = {dataBaseName}_Filestream, FILENAME = '{filePath}') "; |
您使用的是内插字符串。我相信你能做到:
1 2 3 | string createDataBase = $@"CREATE DATABASE {dataBaseName} ON PRIMARY (NAME = {dataBaseName}_Primary, FILENAME = '{primaryPath}'), FILEGROUP {dataBaseName}_FileStreamGroup CONTAINS FILESTREAM(NAME = {dataBaseName}_Filestream, FILENAME = '{filePath}')"; |
如下文所述:C 6中的长字符串插值线