Detect Uninitialized / Empty Array using .Net framework?

  • Thread starter Thread starter Bmack500
  • Start date Start date
B

Bmack500

I have the following bit of code:

j2 = 0
If srvSC(j1) = "XCP CD Proxy" Then
ReDim Preserve badGuys(j2)
badGuys(j2) = j1
j2 += 1
End If

Using .net methods, how can I detect if the badGuys array was never
initialized - even zero times? It throws an exception when I try to do
any kind of test for badguys(0) if it hasn't been given a value!
 
Yes, I tried that - it gives me the following exception: "An unhandled
exception of type 'System.NullReferenceException' occurred in
RootKitDetector.exe"

Additional information: Object reference not set to an instance of an
object.

Any other ideas?
 
If not badGuys is nothing Then
If badGuys.Length = 0 Then
REM No items in array.
End If
Else
REM No reference, badGuys.Length will throw an exception.
End If
 
I'm sorry, I should have thought of that. You can use this:

If (badGuys Is Nothing) OrElse badGuys.Length = 0 Then
'Array is not initialized
End If
 

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

Back
Top