Speaking in Code

Thursday, February 08, 2007

Verbatim String Literal

As a novice C# user, I was recently happy to discover verbatim string literals, which are indicated by the presence of the @-symbol just to the left of
Here's the skinny; when you want to have a large block of text (SQL or XML markup, for example) in your C# code, you can have it formatted exactly the way it is formatted in your SQL or XML editor. This allows for excellent readability and rapid switching between your respective editors and your C# code page. Here is an example; the below SQL equally well in a C# page and an SSMS query editor. It has really sped up my debugging of in-line SQL. As far as I know, VB.NET doesn't have an equivalent feature.


DataSet ds = MyClass.GetData(@"
SELECT 0 AS Field1, '<>' AS Field2
UNION ALL
SELECT
Field1,
Field2
FROM
A_Table
WHERE
[Year] = udfFiscalYear()
ORDER BY
Field2
", "A_Table");

Labels: ,