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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章