473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to check for Undefined Values/Objects in C#

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
10 5887
"=?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
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
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
"=?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
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
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
"=?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
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
"=?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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: niks4ward | last post by:
Hi..could nebody please tell me how do i check if the grid cells are NULL or empty on command button click. m working on VB.Net 2005
0
by: hussainiyad | last post by:
hi to all this is hussain i need ur help. in a datagrid there r two textboxes and a button and a label, if i type any value in that textboxes and click the button if the values r equal then the msg...
0
by: gopikrishna513 | last post by:
hi guys I have a problem in using COM objects in vb.net. on my system i have imported on COM object for my project and build an exe on vb.net project and now the problem arises when i was...
2
by: nuwansl | last post by:
I want to get value from multiple check box but not in array.
2
by: mfaisalwarraich | last post by:
Hi everybody, I am facing great difficulty with my database. My problem is I made a database named ExternalDatabase and then made another database called EntryDatabase. I am reading the data of...
1
by: RP | last post by:
In my Form, I have 20 or 30 Text Boxes and Combo Boxes. I am using a tabbed interface. When the Form's Close button is clicked, I want to check whether user attempted an entry in any of the Text...
9
by: popamit60 | last post by:
Tell me Guys , If there is any Fun to check float numbers in javascript ?? Tell me d solution Thanks Amit
2
by: mrimalka | last post by:
I have few check boxes in first page. this page has form action pointing to one page and href to other page. How can I send check box values to page pointed by href? I am using html/php. ...
3
by: stephenmani | last post by:
Hi, I need to know how to check the login user name and password entered are in the database table that is created for the register purpose. To compare the user name and password of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.