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