How and when to abandon the use of arrays in C#?

后端 未结 15 1732
盖世英雄少女心
盖世英雄少女心 2020-12-13 02:58

I\'ve always been told that adding an element to an array happens like this:

An empty copy of the array+1element is created and then the data from t

15条回答
  •  情书的邮戳
    2020-12-13 03:27

    The best thing you can do is to allocate as much memory as you need upfront if possible. This will prevent .NET from having to make additional calls to get memory on the heap. Failing that then it makes sense to allocate in chunks of five or whatever number makes sense for your application.

    This is a rule you can apply to anything really.

提交回复
热议问题