如何为 string.Format 设置命名参数?
我在调用时遇到 C# 错误:
string.Format(format:"abbccc", 1,22);
错误是“命名参数规范必须在指定所有固定参数之后出现”
如何解决此问题?
[编辑]
我更喜欢使用命名参数。
I have C# error when calling:
string.Format(format:"abbccc", 1,22);
The error is "Named argument specifications must appear after all fixed arguments have been specified"
How can I fix this?
[Edit]
I prefer to use named parameters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要指定格式参数的名称,则还必须指定以下参数的名称:
这不是很有用,因为名称“arg0”和“arg1”根本没有说明有关参数的任何内容。
另外,只有“arg2”以下的重载,因此如果您有更多参数,则必须将它们放入数组中来命名参数:
您可以简单地跳过命名参数:
If you want to specify the name of the format argument, you have to specify the name of the following argument also:
That's not very useful, as the names "arg0" and "arg1" doesn't say anything at all about the arguments.
Also, there are only overloads up to "arg2", so if you have more arguments, you have to put them in an array to name the argument:
You can simply skip naming the arguments:
就我而言,我必须清理并重建解决方案,这使得错误消失。发生的事情是,我添加了一个像这样的参数
,我收到了触发器错误,所以我删除了 JobDetail:,语法错误消失了,但复杂化后我仍然收到错误
我清理了解决方案并重建,错误消失了。
In my case, I had to Clean and Rebuild the solution, that made the error go away. What happened was, I added an argument like this
I was getting an error for trigger, so I removed, JobDetail:, and the syntax error go away but on complication I was still getting the error
I cleaned the solution and rebuilt and the error went away.