当前位置:网站首页>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 .
边栏推荐
- Alibaba cloud award winning experience: build a highly available system with polardb-x
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
- Reading cognitive Awakening
- 2022KDD预讲 | 11位一作学者带你提前解锁优秀论文
- PostgreSQL 9.1 飞升之路
- 比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟
- Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
- Agile development / agile testing experience
- DGraph: 大规模动态图数据集
猜你喜欢
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
光环效应——谁说头上有光的就算英雄
Comparative study of the gods in the twilight Era
6 分钟看完 BGP 协议。
HAProxy高可用解决方案
Oracle was named the champion of Digital Innovation Award by Ventana research
Master the use of auto analyze in data warehouse
CTF competition problem solution STM32 reverse introduction
CVPR 2022 | transfusion: Lidar camera fusion for 3D target detection with transformer
Alibaba cloud award winning experience: build a highly available system with polardb-x
随机推荐
runc hang 导致 Kubernetes 节点 NotReady
Two dimensional code coding theory
Optional values and functions of the itemized contenttype parameter in the request header
再说rsync+inotify实现数据的实时备份
6 分钟看完 BGP 协议。
游戏启动后提示安装HMS Core,点击取消,未再次提示安装HMS Core(初始化失败返回907135003)
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)
Cors: standard scheme of cross domain resource request
HAProxy高可用解决方案
高效!用虚拟用户搭建FTP工作环境
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
C#基础深入学习一
Don't turn down, three sentences to clarify the origin of cross domain resource request errors
使用宝塔部署halo博客
读《认知觉醒》
ASP.NET Core入门一
The old-fashioned synchronized lock optimization will make it clear to you at once!
6 分钟看完 BGP 协议。
Talk about the design and implementation logic of payment process
Definition of cognition