Upon learning Unity (and C#) for a month, I’ve noticed how all tutorials and beginner stuff basically make you use arrays. However, when I started working on my own project and googling and checking around, I’ve seen that almost everybody use lists instead of arrays more often, mentioning that lists are more flexible and effective.
Is definitely better to learn how to use lists instead of arrays? Right now I’m using plenty of arrays because that’s what I’ve been taught to initially (actually I’m using arrays of arrays). So, maybe I should do everything as lists before getting too much ahead. Thanks for the tips!
Arrays are technically more performative, as long as you’re using them in situations with static length and generally in loop format where you’re accessing every item (otherwise a Dictionary would be more performant).
There’s a good chance you could go from where you’re at to having a successful job writing code for a living and never need to worry about the real-world performance implications of arrays vs lists. It’s not until those situations where you do need to worry about those extra milliseconds that knowing which to use when really comes in handy.
So while it’s good practice to make sure you’re getting that stuff right now, it’s also arguably just as important that the most important thing when you’re starting out is to persist in the learning and experience efforts, and getting work moving along (and eventually completing). With that in mind, Lists are generally easier to work with and provide some useful built-in methods that arrays lack (without casting) so if you like using them, continue to do so. If you’re not using them and prefer arrays, that’s fine, but it’s worth knowing what lists, dictionaries, and hashsets can do for you so you don’t spend time reinventing the wheel adding functionality to data you’re storing in arrays.
4 Likes
Thanks for the well thought response! Because I need to grind what I’ve learned to really assimilate it properly, I’ll stick with arrays for the time being – I’ll check here and there videos about lists and dictionaries in the meantime. Looking forward for more!
1 Like
Lists are generally more flexible and convenient. My personal recommendation would be to default to using a List between the two, unless you specifically need the slight performance improvement of an array.
1 Like