NAV 2009 R2 .Net Interop: using arrays / collections (2)

Remember my post about ".Net Interop: using Arrays and Collections" (not too long ago)? Well, almost immediately i got a comment from Freddy (Kristiansen) explaining that the Dictionary that I used, is actually quite an expensive one.. . It actually uses two collections (one for the key to find the Index, second for the value with that index), which causes for overhead in case you don't actually need it for your software. When using arrays for lots of data, you might want to consider to use Lists or ArrayLists instead.. .

In both cases, the code looks alike .. . Something like this for Lists:

And this for ArrayLists:

Quite identical, isn't it?

The big difference when using these in stead of using a dictionary is the fact that you're using a real index as key (and not a definable index as in a dictionary).

But what is the difference between a List and an ArrayList?

I'm actually not sure it makes big of a difference for AL developers like us. In C#, this would be the explanation:

  • ArrayList stores everything as an object, and when you retrieve the value you have to cast it back into the actual object type if you want to use any of the objects methods, etc.
  • List is a generic container type that you specify what type it can hold when you instantiate the List<T>. You don't have to cast the object back into the type.

I hope this is sufficient for an explanation. If you have something to contribute .. please feel free to drop a comment!

Comment List