Null vs undefined

T

tshad

I have a structure (which happens to be a Java DataBean that contains some
string arrays) that is giving me an error.

The error at the "for" statement is:

Object reference not set to an instance of an object.

Here is the code where chDataBean is the structure.
chDataBean.voucherNumber is a string array of voucher numbers. But if there
are no numbers the debugger shows it as <undefined value>. But other fields
are showing as null in the debugger. What is the difference? How would I
test for each one? I assume I would have to do a test before the "for"
statement, since that is where I am getting the error.
***************************************************************
chDataBean = checkHistoryService.readCheckHistory(
elDataBean.employeeIds[ktr],
ruDataBean.employerList[1][0],
"2006",
Session.SessionID);

for(ktr1=0;ktr1<= chDataBean.voucherNumber.GetUpperBound(0);ktr1++)
{
GetPayStatementData(ref sCheckLine,objStreamWriter,
elDataBean.employeeIds[ktr],chDataBean.voucherNumber[ktr1],chDataBean.payDate[ktr1],
ruDataBean.employerList[1][0],eDataBean);
}
************************************************************************

Thanks,

Tom
 
J

Jon Skeet [C# MVP]

tshad said:
I have a structure (which happens to be a Java DataBean that contains some
string arrays) that is giving me an error.

The error at the "for" statement is:

Object reference not set to an instance of an object.

Here is the code where chDataBean is the structure.
chDataBean.voucherNumber is a string array of voucher numbers. But if there
are no numbers the debugger shows it as <undefined value>. But other fields
are showing as null in the debugger. What is the difference? How would I
test for each one? I assume I would have to do a test before the "for"
statement, since that is where I am getting the error.

They're the same thing - I don't know why the debugger shows them
differently, although it might be that it shows local variables which
have been assigned a value as null, but local variables which just
haven't been assigned yet as "undefined value".

Comparing with null would be better in either case.

By the way - if your array is a one-dimensional one, using
GetUpperBound is a bit messy compared with:

for (ktr1=0; ktr1 < chDataBean.voucherNumber.Length; ktr1++)
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


They're the same thing - I don't know why the debugger shows them
differently, although it might be that it shows local variables which
have been assigned a value as null, but local variables which just
haven't been assigned yet as "undefined value".


I think that both the debugger and the intellisense display <undefined
value> instead of null either way
 
T

tshad

Jon Skeet said:
They're the same thing - I don't know why the debugger shows them
differently, although it might be that it shows local variables which
have been assigned a value as null, but local variables which just
haven't been assigned yet as "undefined value".

Comparing with null would be better in either case.

Great.

By the way - if your array is a one-dimensional one, using
GetUpperBound is a bit messy compared with:

for (ktr1=0; ktr1 < chDataBean.voucherNumber.Length; ktr1++)
Why?

Tom
 
T

tshad

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,





I think that both the debugger and the intellisense display <undefined
value> instead of null either way

Actually, I am looking at a structure and am getting something like:
field1 null
field2 null
field3 null
field4 <undefined value>
field4 <undefined value>
field3 null
field4 <undefined value>
field3 null
field4 <undefined value>
....

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top