Casting null as an object?

懵懂的女人 提交于 2019-12-23 06:48:05

问题


I came across this code today

AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null);

Is there anything wrong with it or no?


回答1:


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.




回答2:


it probably needs the cast to resolve overloads



来源:https://stackoverflow.com/questions/358079/casting-null-as-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!