当前位置:网站首页>C array supplement
C array supplement
2022-07-04 13:42:00 【Hua Weiyun】
c# A few simple additions to the array
An array is a reference type , Whether its element is a value type or a reference type .
c# Various interfaces implemented by array objects in :
// Defines the ability of shallow copy , So arrays can be shallow copied System.ICloneable// ICollection Interface descendants , Use interface programming to reduce coupling , This interface only defines some methods , With indexer , Query element location , insert data , Remove the index location data , It can be simply used as a container for storing data , Can not be like List That has a lot of data processing methods .System.Collections.IList// The parent base class of the collection , Defines the number of return elements , Some of the most basic methods of collection types, such as copying , At the same time, it provides synchronous access ICollection Methods of object elements , Arrays have these capabilities System.Collections.ICollection// Define the ability of iterative traversal , Arrays can be used foreach loop System.Collections.IEnumerable// .net4 New interface , Defines the ability to sort , Data can be sorted, so System.Collections.IStructuralComparable// .net4 New interface , Define comparative capabilities , Array can compare whether the array has the same content. If the number of elements is different, it directly returns unequal , Having several elements at the same time will perform several comparisons System.Collections.IStructuralEquatable// Indexers are also provided , There are several ways to delete and insert query data , But it's generic data /* special , By default, all arrays inherit from Array abstract class , This class implements the above interface , But when looking at the source code, you can't see that the array implements the following interfaces , These interfaces are really CLR Dynamically implement the following interfaces for one-dimensional arrays */System.Collections.Generic.IList <T>// The ability to provide generics , It also has the basic function of adding, deleting, modifying and checking System.Collections.Generic.ICollection <T>// A type can use linq iteration , The interface must be changed , So arrays can use linq Inquire about .System.Collections.Generic.IEnumerable <T>// read-only list, Access the read-only through the index list The elements of System.Collections.Generic.IReadOnlyList <T>// Read only set , Access the elements of the read-only collection through the index System.Collections.Generic.IReadOnlyCollection <T>Code view :
foreach (var type in (new int[0,0]).GetType().GetInterfaces()) Console.WriteLine(type);By executing this code , When the array created is a one-dimensional array , The array object will implement the generic interface , You can have linq The ability to query , But when it's not a one-dimensional array , At this time, the data does not have linq The ability of , At this time, the array object does not implement the generic interface .
These movements are made by CLR ( Common language runtime ) Executive , The internal principle is not clear , But in general linq Queries are operations on collections , Arrays belong to collections , But because there are multidimensional arrays , Arrays cannot be implemented directly IEnumerable Generic interface get linq The ability to query , Instead, managed code is run by CLR Responsible for handling , Give interface capabilities to one-dimensional arrays , Non one dimensional arrays cannot have interface capabilities .
Of course, all of the above are for reference types , Value types do not have such operations that dynamically empower interfaces .
边栏推荐
- A data person understands and deepens the domain model
- Iptables foundation and Samba configuration examples
- WPF double slider control and forced capture of mouse event focus
- Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
- 使用宝塔部署halo博客
- 爬虫练习题(一)
- Reinforcement learning - learning notes 1 | basic concepts
- In 2022, it will be es2022 soon. Do you only know the new features of ES6?
- 使用Scrcpy投屏
- 一文掌握数仓中auto analyze的使用
猜你喜欢

ASP.NET Core入门一

Etcd storage, watch and expiration mechanism

实时云交互如何助力教育行业发展

CA:用于移动端的高效坐标注意力机制 | CVPR 2021

Reptile exercises (I)

Oracle 被 Ventana Research 评为数字创新奖总冠军

Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example

聊聊支付流程的设计与实现逻辑

A taste of node JS (V), detailed explanation of express module
![[cloud native | kubernetes] in depth understanding of ingress (12)](/img/34/67eae1e5df89bb0a356a1c29a5e007.png)
[cloud native | kubernetes] in depth understanding of ingress (12)
随机推荐
6 分钟看完 BGP 协议。
C#基础补充
JVM系列——栈与堆、方法区day1-2
面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
2022KDD预讲 | 11位一作学者带你提前解锁优秀论文
Rsyslog configuration and use tutorial
Using nsproxy to forward messages
WPF double slider control and forced capture of mouse event focus
XML入门一
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
实时云交互如何助力教育行业发展
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
Reptile exercises (I)
诸神黄昏时代的对比学习
After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
C#基础深入学习一
ISO 27001 Information Security Management System Certification
CommVault cooperates with Oracle to provide metallic data management as a service on Oracle cloud
Iptables foundation and Samba configuration examples
洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通