C#中使用$替換string.Format


最近工作中,遇到了一個問題,最后發現是在使用string.Format的時候,由於查詢條件太多,導致賦值的時候出錯。

string sqlOne = string.Format(@" select * from MD_Person  where Code='{0}' AND Role=N'{1}' AND Type=N'{2}'", code, role, type);

這種寫法,當查詢條件特別多的時候,容易出錯。

最后將string.Format都是用$來替換

string sqTwo = $"select * from MD_Person where Code='{code}' AND Role='{role}' AND Type='{type}'";

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM