Last post Nov 10, 2016 02:08 PM by ManOfManyHats
Nov 09, 2016 07:15 PM|ManOfManyHats|LINK
So, I need to determine if my hashtable is null, and the only way I could figure out
how to do it is with a try catch of System.NullReferenceException as shown below.
would you know a better way?
Dim info_hash As Hashtable
If Not info_hash.Contains(inName & "," & inTitle) Then 'has at least one entry
'just testing to see if NullReferenceException thrown
Catch Nullex As System.NullReferenceException
'has no entries yet, so perform the first info crunch and this will also populate the info_hash
Nov 09, 2016 07:35 PM|Mikesdotnetting|LINK
Dim info_hash As HashTable
If Not info_hash?.Contains(inName & "," & inTitle) Then
Null Conditional Operator:
Nov 09, 2016 08:23 PM|ManOfManyHats|LINK
Thanks for the response, but this did not work for me, my hashtable is showing up as NOTHING yet your if statement did not hit upon that.
Nov 09, 2016 10:18 PM|Mikesdotnetting|LINK
my hashtable is showing up as NOTHING yet your if statement did not hit upon that.
Nov 09, 2016 10:45 PM|PatriceSc|LINK
For now my understanding is that you are looking for :
If Info_hash is nothing then ' if the object is a null reference then do something etc...
Also when dealing with "lists" it its very common to just initialize the list when it is declared :
Dim info_hash As New Hashtable
Then the main code can check if an element is found, add elements or check if the list is empty without having to ensure first that the list itself is initialized.
Nov 10, 2016 02:08 PM|ManOfManyHats|LINK
Thanks, that was my problem, I need to initialize the list.