ToString() returns null?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 19:01:29

I don't know of any types where it does. It's not impossible - it would certainly be easy to write your own type which behaved like that - but I doubt any of the framework types do.

Do you have any particular types in mind?

EDIT: DateTime.ToString(invariantCulture) should never return null - the culture settings should be irrelevant, if you've really got the invariant culture.

Correction, Object is not null if it returns null, NPE will thrown for null Object before toString() will be even tried to be invoked :)

Jeffrey Kevin Pry

You can also override the ToString() method and assign it a custom value. If it returns null still, then the object is null.

http://msdn.microsoft.com/en-us/library/ms173154%28v=vs.80%29.aspx

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