且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

差异b / w数组和c#中的arraylist

更新时间:2023-02-03 19:05:12

基本区别在于数组的大小是固定的。而ArrayList实现了列表数据结构,并且可以动态增长。虽然数组比列表更具性能,但列表更灵活,因为您最初不需要知道所需的大小。
Basic difference is that arrays are of fixed size. Whereas an ArrayList implements the list data structure and can dynamically grow. While arrays would be more performant that a list, a list would be far more flexible since you don't need to know the required size initially.


从这里提取:

http://***.com/questions/128636 / net-data-structures-arraylist-list-hashtable-dictionary-sortedlist-sorted [ ^ ]







数组 - 代表一个老式的内存数组 - 有点像普通类型[]数组的别名。可以列举。无法自动增长。我会假设非常快速的插入和回溯。速度。



ArrayList - 自动增长阵列。增加更多开销。可以枚举。,可能比正常数组慢,但仍然相当快。这些在.NET中被大量使用



列表 - 我最喜欢的一个 - 可以用于泛型,所以你可以强烈使用类型数组,例如列表与LT;串取代。除此之外,其行为与ArrayList非常相似。



Hashtable - 普通的旧散列表。 O(1)到O(n)最坏的情况。可以枚举值和键属性,并执行键/值对。



词典 - 与上面相同,只能通过泛型强类型,例如as Dictionary< string,>



SortedList - 排序的通用列表。插入速度慢,因为它必须弄清楚放置的位置。可以枚举。,在检索时可能是相同的,因为它不需要求助,但删除将比普通的旧列表慢。
Extracted from here :
http://***.com/questions/128636/net-data-structures-arraylist-list-hashtable-dictionary-sortedlist-sorted[^]



Array - represents an old-school memory array - kind of like a alias for a normal type[] array. Can enumerate. Can't grow automatically. I would assume very fast insertion and retriv. speed.

ArrayList - automatically growing array. Adds more overhead. Can enum., probably slower than a normal array but still pretty fast. These are used a lot in .NET

List - one of my favs - can be used with generics, so you can have a strongly typed array, e.g. List<string>. Other than that, acts very much like ArrayList.

Hashtable - plain old hashtable. O(1) to O(n) worst case. Can enumerate the value and keys properties, and do key/val pairs.

Dictionary - same as above only strongly typed via generics, such as Dictionary<string,>

SortedList - a sorted generic list. Slowed on insertion since it has to figure out where to put things. Can enum., probably the same on retrieval since it doesn't have to resort, but deletion will be slower than a plain old list.


-Array具有固定大小但是Arraylist是一个数据结构可以动态增长和缩小。



-Array是在堆栈内存中创建的,其中Arraylist被创建并存储在堆区域中。
-Array is of fixed size but Arraylist is a datastructure which can dynamically grow and shrink.

-Array is created in stack memory where Arraylist is created and stored in heap area.