By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,025 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,025 IT Pros & Developers. It's quick & easy.

How to check for Undefined Values/Objects in C#

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:54**********************************@microsof t.com:
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/
Nov 17 '05 #2

P: n/a
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

"Chad Z. Hower aka Kudzu" wrote:
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:54**********************************@microsof t.com:
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/

Nov 17 '05 #3

P: n/a
mdb
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:EB**********************************@microsof t.com:
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"; } .....

--
-mdb
Nov 17 '05 #4

P: n/a
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:EB**********************************@microsof t.com:
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/
Nov 17 '05 #5

P: n/a
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" wrote:
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:EB**********************************@microsof t.com:
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/

Nov 17 '05 #6

P: n/a
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" wrote:
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:EB**********************************@microsof t.com:
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"; } .....

--
-mdb

Nov 17 '05 #7

P: n/a
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:E6**********************************@microsof t.com:
This is an object of type user define datatype which returns row data
via web services.


But what class type is sObject? Its it an array? An object with an index property?
--
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/
Nov 17 '05 #8

P: n/a
Yes, this object is of type array.

"Chad Z. Hower aka Kudzu" wrote:
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:E6**********************************@microsof t.com:
This is an object of type user define datatype which returns row data
via web services.


But what class type is sObject? Its it an array? An object with an index property?
--
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/

Nov 17 '05 #9

P: n/a
"=?Utf-8?B?TS4gVXBwYWw=?=" <MU****@discussions.microsoft.com> wrote in
news:C2**********************************@microsof t.com:
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/
Nov 17 '05 #10

P: n/a
M. Uppal <MU****@discussions.microsoft.com> wrote:
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...)

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

This discussion thread is closed

Replies have been disabled for this discussion.