C# string.Format谨慎使用

string.Format

string.Format在处理文本的时候很有用处,但是在使用占位符的时候一定要注意内容中的特殊字符{}

示例

string.Format("你好{0},这是{1}",name,adress);//这样肯定是没有问题的。
string shijian="现在是:{"+DateTime.Now.toString()+"}";
string.Format("你好{0},这是{1}"+shijian,name,adress);//这样就会出问题了,因为内容中有不规范的展位符。

异常信息

请输入正确的字符传!

原文地址:https://www.cnblogs.com/huhangfei/p/5000803.html