The code I’m writing receives an ArrayList from unmanaged code, and this ArrayList will always contain one or more objects of type Grid_Heading_Blk. I’ve considered changing this ArrayList to a generic List, but I’m unsure if the conversion operation will be so expensive as to nullify the benefits of working with the generic list. Currently, I’m just running a foreach (Grid_Heading_Blk in myArrayList) operation to work with the ArrayList contents after passing the ArrayList to the class that will use it.
Should I convert the ArrayList to a generic typed list? And if so, what is the most efficient way of doing so?
Here’s a stab at a performant way to create a generic list from an ArrayList.
By calling the constructor that accepts an int, the backing storage is allocated only once.
As always, you should measure the performance using whatever tools you normally use.