Most efficient way to append arrays in C#?

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.

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

Answers


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.

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


Need Your Help

AnkhSVN & DiffMerge Not Saving Changes

svn merge ankhsvn diffmerge sourcegear

I'm using Ankh SVN 2.4.11610.27 for Visual Studio 2010 and it works decently enough.

Inline divs with vertical lists

css html cross-browser html-lists

I'm trying to design a footer section for my website, and I'm having trouble with cross-browser compatible solutions. I need a way to display inline divs with vertical lists inside them. eg.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.