当前位置:网站首页>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 .
边栏推荐
- Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things
- 浅析Redis 切片集群的数据倾斜问题
- C # define and implement interface interface
- Maui uses Masa blazor component library
- unity防止按钮btn被连续点击
- 基于SSH框架甜品商城管理系统【源码+数据库】
- JasperReport报表生成工具的基本使用和常见问题
- Is the encryption market a "natural disaster" or a "man-made disaster" in the cold winter?
- Should programmers choose software talent outsourcing companies?
- 快速了解常用的对称加密算法,再也不用担心面试官的刨根问底
猜你喜欢

【无标题】
Redis+Caffeine两级缓存的实现

Is the encryption market a "natural disaster" or a "man-made disaster" in the cold winter?

Maui uses Masa blazor component library

Stm32f1 and stm32subeide programming example - Optical intermittent sensor drive

CVE-2022-22965複現

Basic usage and FAQs of jasperreport report report generation tool

Traffic replication in istio Service Grid

【Pr】基础流程

Cat agile team coaching workshops - August 20
随机推荐
If you want to know the stock account opening discount link, how do you know? Is it safe to open an account online?
Stm32f1 and stm32subeide programming example - Optical intermittent sensor drive
Z-Score和deltf/f有什么区别?
MadCap Flare 2022,语言或格式的文档
Tianrun cloud is about to be listed: VC tycoon Tian Suning significantly reduces his holdings and is expected to cash out HK $260million
As a passer-by, some advice for programmers who are new to the workplace
Technology practice | scene oriented audio and video call experience Optimization
天润云上市在即:VC大佬田溯宁大幅减持,预计将套现2.6亿港元
浅析Redis 切片集群的数据倾斜问题
What is the difference between Z-score and deltf/f?
ThoughtWorks.QRCode和ZXing.Net 二维码,网址可以直接跳转
机器学习之随机森林
How maxscale handles event status after MariaDB master-slave switchover -handle_ events
How to understand fold change? Multiple analysis?
Unity sub thread calls UI of main thread
如何给VR全景作品添加遮罩?作用是什么?
How to compare the size of two dates in unity and C #
php两个时间戳相隔多少天
安装和使用protobuf-c
uniapp app 端截屏且保存到本地