最有效的方法追加在C#中的数组? [英] Most efficient way to append arrays in C#?

查看:687
本文介绍了最有效的方法追加在C#中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在双打的阵列的形式拉动数据从一个老派的ActiveX。我不知道最初的样本的最终数目,我会实际检索。

I am pulling data out of an old-school ActiveX in the form of arrays of doubles. I don't initially know the final number of samples I will actually retrieve.

什么是C#作为我拉出来的系统来连接这些阵列在一起的最有效的方法是什么?

What is the most efficient way to concatenate these arrays together in C# as I pull them out of the system?

推荐答案

您不能追加到实际的数组 - 一个数组的大小是固定的创建时间。相反,使用列表< T> ,因为它需要它可以长到

You can't append to an actual array - the size of an array is fixed at creation time. Instead, use a List<T> which can grow as it needs to.

另外,保持阵列的列表,以及所有将它们连接起来,只有当你已经抓住了一切。

Alternatively, keep a list of arrays, and concatenate them all only when you've grabbed everything.

请参阅Eric利珀特对阵列博客文章的更多细节和见解比我能切实提供:)

See Eric Lippert's blog post on arrays for more detail and insight than I could realistically provide :)

这篇关于最有效的方法追加在C#中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆