Suppose I have a loop which is going to convert an ArrayList with 10 million elements, filled with int, to an array of string. Should I be using Convert.ToString(...) or Object.ToString()? Is it true that in this case Convert.ToString(...) unboxes the elements and decreases the performance?
If you've got an ArrayList, any value types will already be boxed. Why are you using ArrayList rather than a List<int>? The latter will avoid both the execution time cost of boxing and the significant space implications.
After changing to use List<int> however, I'd then just call ToString. It says exactly what you want to do in a simpler way than Convert.ToString, IMO... and provides more formatting options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With