sqlStr = @"select count(*) as Total from [PCS_OfferPriceBills] ";
C# 字符串前的 @什么意思: string sqlStr = @"select count(*) as Total from [PCS_OfferPriceBills] "; sqlStr = sqlStr + " where " + @strWhere;
不转移字符当做字符串处理。 如string ss = @"aa\naa";输出 aa\naa; 而string ss = "aa\naa";输出 aa aa
C# string 字符串的前面可以加 @(称作“逐字字符串”)将转义字符(\)当作普通字符对待,比如:
string str = @"C:\Windows";
如果我们去掉 @ 的话,应该是:
string str = "C:\\Windows";
@ 字符串中,我们用两个连续英文双引号表示一个英文双引号,如下字符串的实际内容为:="=,字符串长度为 3。
string str = @"=""=";
@ 字符串中可以任意换行,换行符及缩进空格都计算在字符串长度之内。
string str = @"<script type=""text/javascript"">
<!--
-->
</script>";
<!--
-->
</script>";
由于 @ 的这种特性,我们常将其应用到 SQL 字符串中。
string sql = @"select * from tbl";
@ 只在连续一段字符串中有效,@"abc" + "\\",用 + 将两个字符串连接起来,第二个字符串中没有用 @ 标识,其中的 \ 就成为转义字符。