c#中@和$对字符串的用法

 一、@的用法:

1.忽略转义符

string strPath = "C:\\HelloWorld\\bin";

string strPath = @"C:\HelloWorld\bin";

2.跨行

string strSql = "SELECT * FROM Custom  "

  + " where  id=123";

string strSql = @"SELECT * FROM Custom where

   id=123";

二、$的使用

string custid = 123;

string strSql = $"slect * from custom where id={custid}";

三、混合使用

string custid = 123;

string strSql =$ @"slect * from custom where

                                 id={custid}";

 

 

发布了116 篇原创文章 · 获赞 37 · 访问量 41万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章