泛型类型的默认参数,实例化为 int 时为“null”;根据智能感知
出于好奇,以下是错误还是预期行为?恕我直言,整数参数的默认参数是 null 似乎很奇怪。
Out of curiosity, is the following a bug or intended behavior? It seems IMHO strange that the default argument of an integer parameter is null
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是您的 IDE 显示不正确;如果代码编译正确,您可能需要打印该函数中的参数,以确保获得您期望的默认值。
我愿意打赌它会按预期运行。
This could be your IDE displaying it improperly; if the code compiles properly, you might want to print the argument in that function, to ensure that you're getting the default value that you expect.
I would be willing to bet that it is functioning as intended.
在我的计算机 VS Professional 2010(面向 .Net 4.0)上,它具有正确的信息
int arg = Default(T)
。所以,我想你不会发疯:)On my computer, VS Professional 2010, targeting .Net 4.0, it has the correct information
int arg = Default(T)
. So, I suppose you are not going crazy :)