C#中$的用法


C#中$的用法是c#6.0后新增的特性,用于代替string.Format(""),例如:

string strWhere="";

strWhere += string.Format(" and w.Id={0}", searchKeys["Id"].ToString());
strWhere += $" and w.Id={searchKeys["Id"].ToString()}";
strWhere += $" and w.Id='{searchKeys["Id"].ToString()}'";
strWhere += $" and w.Id=\"{searchKeys["Id"].ToString()}\"";

以上四种写法效果一致。

注:C#6.0 .NET Framework4.6  Visual Studio 2015   


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM