+ 3

Array vs Collection in C#

I know, that in C#a collection can change its length dinamically, but that leads to the question what the benefits of an array over a (dictionary) collection is. Hope this question isn't that stupid ;D

10th Apr 2018, 11:47 AM
DaEistee
4 Answers
+ 9
First of all, I believe you're referring to List<T> in C# instead of Dictionary<TKey, TValue> as the latter is a list of key-value pair. As you might already know, an array always have a fixed size and the convenience of flexible size of list comes with a trade-off in terms of performance. Therefore, use an Array if you are certain the size beforehand and List in any other cases. Hopefully it helps! šŸ˜‰
10th Apr 2018, 1:21 PM
Zephyr Koo
Zephyr Koo - avatar
+ 1
Well, arrays are somewhat faster.It's all about performance.
10th Apr 2018, 1:21 PM
Hallox
Hallox - avatar
+ 1
Alright then, thank you guys for the fast answer :)
10th Apr 2018, 2:10 PM
DaEistee
0
Exactly :)
10th Apr 2018, 1:22 PM
Hallox
Hallox - avatar