当前位置:网站首页>Differences and performance of array, list, ArrayList, directory and LinkedList in C #
Differences and performance of array, list, ArrayList, directory and LinkedList in C #
2022-06-22 14:36:00 【Singing folk songs on the grassland】
Array :int[] count = new int[10];
List:List<int> list = new List<int>;
ArrayList:ArrayList arrayList = new ArrayList();
Dictionary:Dictionary<string, int> dire = new Dictionary<string, int>();
LinkedList:LinkedlList<string> linkedList = new LinkedList<string>();
analysis :
From the above initialization, we can see , These types are all reference types . Where array 、List、Dictionary and LinkedList The element type needs to be specified during initialization ( The array also needs to specify its size ), and ArrayList There is no need to specify its type during initialization .
Array : Its size and type must be specified during initialization , It is stored continuously in memory , So we can see that the indexing speed of the array is very fast . After determining the length and type of the array , Choosing an array to store data is a good choice . Not suitable for insert operation .
List: The data type of the objects in the collection must be specified during initialization , But you don't need to specify the size , It won't look like ArraryList That will cause packing and unpacking operations in the process of access , Avoid type insecurity . In the case of the same type ,List And the performance of array . Easy to insert .
ArrayList:ArrayList stay System.Collections Under the namespace , At the same time inherited IList Interface .ArrayList The size of the object can be dynamically increased or decreased according to the stored data , There is no need to specify its size and type during initialization . It is troublesome to insert data between two data for an array , And its size must be determined during initialization , therefore C# Provide ArrayList Overcome these shortcomings , It can store different data types , All data accessed will be converted into object type , Easy to insert , But when accessing and retrieving value types , It will cause packing and unpacking , Reduced performance , meanwhile ArrayList There is no implementation of generics , It's not type safe , When processing data, it is very likely to produce data mismatch errors .
Dictionary: Its type must also be specified during initialization , And it also needs to specify a Key, And this Key Is the only one. . Because of this ,Dictionary The indexing speed of is very fast . But also because it adds a Key,Dictionary It takes up more memory space than other types . It's through Key To find the , The order of the elements is indeterminate .
LinkedList: Both arrays and array lists have a major flaw , This is the cost of removing an element from the middle of the array , The reason is that all elements in the array after the deleted elements are moved to the front of the array . The same goes for inserting an element in the middle of an array .
边栏推荐
猜你喜欢

Nine good programming habits for 10 years

一文彻底弄懂建造者模式(Builder)

Unity商业游戏常用真机调试插件

Should programmers choose software talent outsourcing companies?

CVE-2022-22965複現

Cve - 2022 - 22965 Resume

How to implement interface exception scenario testing? Exploration of test methods and implementation of test tools

如何理解fold change?倍数分析?

防火墙基础之策略部署

Installing and using protobuf-c
随机推荐
Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things
能让Jellyfin直接挂载阿里云盘的aliyundrive-fuse
Do you know the scope and process of software project acceptance testing?
如何保护WordPress网站免受网络攻击?采取安全措施至关重要
C# Winform 相册功能,图片缩放,拖拽,预览图分页
《Kubernetes监控篇:Grafana通过自动化方式添加datasource和dashboard》
Analysis on data skew of redis slice cluster
ThoughtWorks.QRCode和ZXing.Net 二维码,网址可以直接跳转
History of hash index design
数据采集之:巧用布隆过滤器提取数据摘要
Unity sub thread calls UI of main thread
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-5
C#泛型方法
Offline physical stores combined with VR panorama make virtual shopping more realistic
Installing and using protobuf-c
Madcap flare 2022, documentation in language or format
Implementation of redis+caffeine two-level cache
3dMax建模笔记(一):介绍3dMax和创建第一个模型Hello world
SQL Server common functions
Loot、USDT