ram*_*ram 2 .net c# string string.format
有什么方法可以在编译时检查格式字符串吗?
例子:
Console.WriteLine("{0} is a really {1} site", "stackoverflow.com", "cool");//this will run
Run Code Online (Sandbox Code Playgroud)
//这将给出一个异常,因为只提供了一个参数
Console.WriteLine("{0} is a really {1} site", "stackoverflow.com");
Exception:"Index (zero based) must be greater than or equal to zero and less than the size of the argument list."
Run Code Online (Sandbox Code Playgroud)
如果格式字符串的格式不正确(即此处 1 之后缺少“}”)
Console.WriteLine("{0} is a really {1 site", "stackoverflow.com","cool");
Exception: Input string was not in a correct format.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1222 次 |
| 最近记录: |