gpt4 book ai didi

c# - C# 中需要 String.Format 以抛出参数不匹配的编译时错误

转载 作者:太空狗 更新时间:2023-10-30 00:26:36 26 4
gpt4 key购买 nike

当传递给 C# 中的 String.Format 的参数数量不匹配时,是否有任何方法可以添加自定义编译时错误

例如:

String.Format("{0} and {1} are my pets", animal);

上面这行应该抛出一个错误,因为我们只传递了一个参数 "animal" ,而它期望有两个 {0},{1}.. 但是实际上,它只会抛出运行时错误。

最佳答案

FxCop/Code Analysis 会发现这一点。是的,您可以在编译时在 VS Premium/Ultimate 中执行此操作。

enter image description here

关于c# - C# 中需要 String.Format 以抛出参数不匹配的编译时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10350354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com