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}'";

 

posted @ 2020-04-27 11:11  算盘  阅读(1466)  评论(0编辑  收藏  举报