|
Hi Everyone, I was wondering if someone could help me ....again? I have an array that gets populated with data. Now depending if there is any data, the array may have some items in it or it may not have any at all. I need to find out if the array has items in it, and if it does command 1 will execute, if it doesn't command 2 will execute. My problem is I am having trouble finding out if the array contains any items or not. How do I find out if the array has data? Thanks in advance! Jay |
Loading

Mahesh ChandRank #1 · 393.3K reputationPosted Sep 5, 2008, 5:30 AM EDT
Array.Length property will tell you if items are > 0 that means it has data.
Jay62 reputationPosted Sep 5, 2008, 6:35 AM EDT
Hi,
I tried that and I get an error that says "Object reference not set to an instance of an object."
my code looks like....
string[] customPartNumbers = pd.CustomPartNumbers; if (customPartNumbers.Length > 0){
command 1
}
else
{
command2
}
The error points at the argument I have in the IF statement.
Is there something I am missing?
AlanRank #669 · 3.6K reputationPosted Sep 5, 2008, 9:54 AM EDT
It sounds like your array may be null rather than just empty. Try changing your if condition to this:
if (customPartNumbers != null && customPartNumbers.Length > 0)
Jay62 reputationPosted Sep 5, 2008, 10:58 AM EDT
You are 100% right Alan! You the man once again! Thanks alot!!
Jay