Problem with hashtable

I’m using a hashtable to store some Objekts (Type NTRIPsource )
after storing a few i want to build a drop down list:


            For Each source As NTRIPsource In mvarGlideTmpSourceTable
                mvarGlideDropMountPoint.Options.Add(source.Mountpoint)
            Next

when reaching the For Each… i get a error:

i have no idea…

Thanks

Enumerating a Hashtable returns DictionaryEntry objects. You can then extract the key and/or value from that.

Here is some psuedo VB


For Each entry as DictionaryEntry in mvarGlideTmpSourceTable
  Dim source as NTRIPsource = CType(entry.Value, NTRIPsource)
  mvarGlideDropMountPoint.Options.Add(source.Mountpoint)
Next

1 Like

@ taylorza - thanks
some times to blind to find the own mistakes

@ VB-Daniel - Pleasure. I just saw I have a typo in the CType, but it is too hard to edit on the mobile, sorry about that.

Why does VB allow implicit casting like that? In C#, that code wouldn’t even compile, and you’d get intelliSense warnings.

VB has an option which controls how strictly the compiler enforces compile time type checking. The default is to have the type checking relaxed, though I always recommend ‘Option Strict’ is enabled at the project level in which case VB is more in line with C# with regard to the compile time type checking.

The more relaxed type checking and optional parameters is what made VB so much more convenient when working with COM components, and which C# has introduced both concepts firstly the relaxed compile time type checking in the form of ‘dynamic’ not supported on .NETMF and finally support for default arguments.

allways the better way to use the “option strict” and use the function to convert.
Finding bugs depending on implicite conversion is realy hard…
when coding a conversion like “Dim b as byte = cbyte(i as integer)” you allways thinking about limits

C# also has a similar “as” syntax for reference types.

var x = someObject as string;

is the same as

var x= (someObject is string) ? (string)someObject : (string) null;