处理空值 [英] Dealing with Null Values

查看:75
本文介绍了处理空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我越来越感到沮丧的是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 null
values. Rather than try to deal with it on a hit-or-miss basis as
exceptions pop up, I thought I should try to learn exactly how C# deals
with null. Of course, there''s nothing obvious in the docs like "Dealing
with Null Values" and a search on "null" yielded 500 results, most of
which don''t apply. Can anybody point me in the right direction? Or offer
some 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!

推荐答案

Max Sandman< sa ********* @ yahoo.com>写道:
Max Sandman <sa*********@yahoo.com> wrote:
我越来越对C#及其对null值的例外感到沮丧。当弹出异常时,我不应该试图在命中或错过的基础上处理它,我想我应该尝试确切地了解C#如何用null来处理
。当然,文档中没有任何明显的内容,例如使用空值处理等文档。并搜索null得到了500个结果,其中大部分都没有申请。任何人都能指出我正确的方向吗?或者提供一些一般性的指导方针?甚至是正确的关键字来搜索文档?
I''m getting increasingly frustrated with C# and its exceptions on null
values. Rather than try to deal with it on a hit-or-miss basis as
exceptions pop up, I thought I should try to learn exactly how C# deals
with null. Of course, there''s nothing obvious in the docs like "Dealing
with Null Values" and a search on "null" yielded 500 results, most of
which don''t apply. Can anybody point me in the right direction? Or offer
some general guidelines? Or even the correct keyword to search the docs?




永远不要尝试取消引用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 probably
won''t always, unfortunately) specify whether or not null is a valid
value for the parameters you pass in, and whether or not the method may
return null.

Basically, make sure you know at all times which of your variables may
be null, and what it means for them to be null. Then don''t dereference
those null values :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too


Hi Max,

嗯,我认为你找不到你想要的东西,现在要问的问题是为什么你的程序中有这么多空值,

你确定你正确地初始化了所有变量吗?你在使用一个对象之前检查

是否为null,这是非常罕见的方法返回null

a值未找到如下例子:


DataRow row = dataset.Tables [" table1"]。Rows.Find(pk);

//我必须检查行是否为有效行或null

if(row!= null){....}

除此之外,我不知道如何建议你。


希望得到这个帮助,


-

Ignacio Machin,

ignacio.machin at dot.state.fl.us < br $> b $ b佛罗里达州交通局


" Max Sandman" < SA ********* @ yahoo.com>在消息中写道

news:uE ************** @ TK2MSFTNGP09.phx.gbl ...
Hi Max,
Well I think that you will not find what you are looking for, now the
question to ask is why you are getting so much null values in your program,
are you sure you initialize all your variables correctly? are you checking
for null before using a object, it''s non uncommon method returning null when
a value is not found like this example:

DataRow row = dataset.Tables["table1"].Rows.Find( pk );
//I have to check if row is a valid row or null
if ( row != null ) { .... }
Other than that, I do not what to advise you.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Max Sandman" <sa*********@yahoo.com> wrote in message
news:uE**************@TK2MSFTNGP09.phx.gbl...
我得到了对C#及其对null值的例外情况越来越感到沮丧。当弹出异常时,我不应该试图在命中或错过的基础上处理它,我想我应该尝试确切地了解C#如何用null来处理
。当然,文档中没有任何明显的内容,例如使用空值处理等文档。并搜索null得到了500个结果,其中大部分都没有申请。任何人都能指出我正确的方向吗?或者提供一些一般性的指导方针?甚至是正确的关键词来搜索文档?

sandman

***通过Developersdex发送 http://www.developersdex.com ***
不要只是参加USENET ......获得奖励!
I''m getting increasingly frustrated with C# and its exceptions on null
values. Rather than try to deal with it on a hit-or-miss basis as
exceptions pop up, I thought I should try to learn exactly how C# deals
with null. Of course, there''s nothing obvious in the docs like "Dealing
with Null Values" and a search on "null" yielded 500 results, most of
which don''t apply. Can anybody point me in the right direction? Or offer
some 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!



关于Nulls ...你有什么挫折?

例子?
with respect to Nulls...what are your frustrations?
examples?
- ---原始消息-----
我对C#及其在nullvalues上的
异常越来越感到沮丧。弹出,而不是试图在命中或
错过的基础上处理它,我想我应该尝试学习
究竟C#如何处理null。当然,在
文档中没有任何明显的东西,例如处理空值。并搜索null产生了500美元b $ b的结果,其中大部分都没有申请。有人能指出我正确的
方向吗?或提供一般指导方针?甚至正确的关键字
搜索文档?
sandman

***通过Developersdex发送 http://www.developersdex.com
***不要只是参加USENET ......获得奖励!
-----Original Message-----
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!
.



这篇关于处理空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆