C# 将 null 转换为对象?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/358079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:23:59 来源:igfitidea点击:
Casting null as an object?
提问by sthay
I came across this code today
我今天遇到了这个代码
AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null);
Is there anything wrong with it or no?
它有什么问题吗?
采纳答案by Brian Genisio
Sometimes, you need to to this when the method is overloaded... to tell the compiler which one you are calling. A null object is still null and it is safe.
有时,当方法重载时,您需要这样做……告诉编译器您正在调用哪个。null 对象仍然是 null 并且是安全的。
回答by Jimmy
it probably needs the cast to resolve overloads
它可能需要演员来解决重载