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

猜你喜欢

转载自www.cnblogs.com/ahao214/p/12785372.html
今日推荐