简体   繁体   中英

Convert.ToString(…) or Object.ToString() for performance

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM