How to check for Undefined Values/Objects in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I need to check for undefined values and objects in C#, which function
should i use. (== null) does not work for undefined objects.

thanks
 
=?Utf-8?B?TS4gVXBwYWw=?= said:
Hi, I need to check for undefined values and objects in C#, which
function should i use. (== null) does not work for undefined objects.

Null is undefined. I've only found a very few instances that ti doesnt work in C# due to conversions
or overrides.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
 
Here is my snipet of code that doesnot work
if (sObject[0] == null) {sLen = "0";} else {sLen =
sObject.Length.ToString();}

where sObject[0] has value of <undefined value>

how else should i make this work.

thanks,

M. Uppal
 
Here is my snipet of code that doesnot work
if (sObject[0] == null) {sLen = "0";} else {sLen =
sObject.Length.ToString();}

Its probably not sObject[0] that is null, but sObject itself. Try this:

if (sObject == null) { sLen = "0"; } .....
 
=?Utf-8?B?TS4gVXBwYWw=?= said:
Here is my snipet of code that doesnot work
if (sObject[0] == null) {sLen = "0";} else {sLen =
sObject.Length.ToString();}

where sObject[0] has value of <undefined value>

What happens when you run it? Do you recieve the error or are you using the watch? The watch window
is sometimes not accurate and displays undefined when in fact it does have a value.

What type is sObject?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 
This is an object of type user define datatype which returns row data via web
services.

I get no error, it simply ignore it.

M. Uppal

Chad Z. Hower aka Kudzu said:
=?Utf-8?B?TS4gVXBwYWw=?= said:
Here is my snipet of code that doesnot work
if (sObject[0] == null) {sLen = "0";} else {sLen =
sObject.Length.ToString();}

where sObject[0] has value of <undefined value>

What happens when you run it? Do you recieve the error or are you using the watch? The watch window
is sometimes not accurate and displays undefined when in fact it does have a value.

What type is sObject?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
 
When i do sObject.Lenght, it tells me there is one record. That is why i am
using sObject[0] which is undefined. This record is returned via web-services.

M. Uppal

mdb said:
Here is my snipet of code that doesnot work
if (sObject[0] == null) {sLen = "0";} else {sLen =
sObject.Length.ToString();}

Its probably not sObject[0] that is null, but sObject itself. Try this:

if (sObject == null) { sLen = "0"; } .....
 
=?Utf-8?B?TS4gVXBwYWw=?= said:
Yes, this object is of type array.

And its an array of what type? What is the declaration of it? The problem I described should not
happen with arrays, but there are certain cases it is possible with implicit conversions.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
 
M. Uppal said:
Here is my snipet of code that doesnot work
if (sObject[0] == null) {sLen = "0";} else {sLen =
sObject.Length.ToString();}

where sObject[0] has value of <undefined value>

how else should i make this work.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

(As you can see, trying to work out the answer by playing twenty
questions can end up taking a long time...)
 
Back
Top