如何在C#中实现多行字符串;VB的XML文字的替代品? [英] How to achieve multi-line strings in C#; an alternative to VB's XML Literals?
本文介绍了如何在C#中实现多行字符串;VB的XML文字的替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在vb.net中有一个使用 XML Literals
来处理大型SQL块,如下所示:
I had a project in vb.net that used XML Literals
to process large blocks of SQL like so:
Dim SQL As String = <a> Use test
alter table BarFoo alter column CouponName nvarchar(328)
alter table Foo alter column IngredientName nvarchar(328)
alter table Bar alter column IngredientShortDescription nvarchar(328)
alter table FooBar alter column ItemName nvarchar(328) </a>.Value
但是似乎找不到与C#等效的语言有什么建议吗?
But cant seem to find its equivalent for C# Any suggestions?
推荐答案
您可以在字符串常量前加上 @
作为前缀以跨越多行.唯一需要转义的就是引号(使用双引号).
You can prefix a string constant with @
to span multiple lines. The only thing that would need to be escaped is quotes (using the double quote).
string SQL = @"Use test
alter table BarFoo alter column CouponName nvarchar(328)
alter table Foo alter column IngredientName nvarchar(328)
alter table Bar alter column IngredientShortDescription nvarchar(328)
alter table FooBar alter column ItemName nvarchar(328)";
这篇关于如何在C#中实现多行字符串;VB的XML文字的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文