本文介绍了处理空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我越来越感到沮丧的是C#及其在null上的异常 值。弹出的原因不是试图按照命中或错过的方式处理它,我想我应该尝试确切地了解C#如何用null处理 。当然,文档中没有任何明显的内容,例如使用Null值处理。并搜索null得到500个结果,大部分是 ,不适用。任何人都能指出我正确的方向吗?或者提供 一些一般指导方针?甚至是搜索文档的正确关键字? sandman ***通过Developersdex发送 http://www.developersdex.com *** 不要只参加USENET。 ..为此奖励!I''m getting increasingly frustrated with C# and its exceptions on nullvalues. Rather than try to deal with it on a hit-or-miss basis asexceptions pop up, I thought I should try to learn exactly how C# dealswith null. Of course, there''s nothing obvious in the docs like "Dealingwith Null Values" and a search on "null" yielded 500 results, most ofwhich don''t apply. Can anybody point me in the right direction? Or offersome general guidelines? Or even the correct keyword to search the docs?sandman*** Sent via Developersdex http://www.developersdex.com ***Don''t just participate in USENET...get rewarded for it!推荐答案 永远不要尝试取消引用null - 那就是你得到例外的时候。 阅读您调用的方法的文档 - 它们应该(但可能是 不一定总是,不幸)指定null是否有效 $ b您传入的参数的$ b值,以及该方法是否可以 返回null。 基本上,请确保您始终知道哪个您的变量可能是为null,以及它们为null的含义。然后不要取消引用 这些空值:) - Jon Skeet - < sk *** @ pobox.com> http://www.pobox.com/~双向飞碟/ 如果回复小组,请不要给我发邮件Never try to dereference null - that''s when you''ll get an exception.Read the documentation for methods you call - they should (but probablywon''t always, unfortunately) specify whether or not null is a validvalue for the parameters you pass in, and whether or not the method mayreturn null.Basically, make sure you know at all times which of your variables maybe null, and what it means for them to be null. Then don''t dereferencethose null values :)--Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet/If replying to the group, please do not mail me too 这篇关于处理空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 16:32