C# List 详解五

目录

26.GetType()    

27.IndexOf(T)    

28.IndexOf(T, Int32)    

29.IndexOf(T, Int32, Int32)    

30.Insert(Int32, T)    

31.InsertRange(Int32, IEnumerable)    

32.LastIndexOf(T)    

33.LastIndexOf(T, Int32)    

34.LastIndexOf(T, Int32, Int32)    


C# List 详解一

1.Add(T),2.AddRange(IEnumerable),3.AsReadOnly(),4.BinarySearch(T),

C# List 详解二

5.Clear(),6.Contains(T),7.ConvertAll(Converter),8.CopyTo(Int32, T[], Int32, Int32),9.CopyTo(T[]),10.CopyTo(T[], Int32)

C# List 详解三

11.Equals(Object),12.Exists(Predicate),13.Find(Predicate),14.FindAll(Predicate),15.FindIndex(Int32, Int32, Predicate),16.FindIndex(Int32, Predicate),17.FindIndex(Predicate)  

C# List 详解四

18.FindLast(Predicate),19.FindLastIndex(Int32, Int32, Predicate),20.FindLastIndex(Int32, Predicate),21.FindLastIndex(Predicate),22.ForEach(Action),23.GetEnumerator(),24.GetHashCode(),25.GetRange(Int32, Int32) 

C# List 详解五

26.GetType(),27.IndexOf(T),28.IndexOf(T, Int32),29.IndexOf(T, Int32, Int32),30.Insert(Int32, T),31.InsertRange(Int32, IEnumerable),32.LastIndexOf(T),33.LastIndexOf(T, Int32),34.LastIndexOf(T, Int32, Int32)    

C# List 详解六

35.MemberwiseClone(),36.Remove(T),37.RemoveAll(Predicate),38.RemoveAt(Int32),39.RemoveRange(Int32, Int32),40.Reverse(),41.Reverse(Int32, Int32)    

C# List 详解七

42.Sort(),43.ToArray(),44.ToString(),45.TrimExcess(),46.TrueForAll(Predicate) 

C# List 详解一_熊思宇的博客-CSDN博客

C# List 详解二_熊思宇的博客-CSDN博客

C# List 详解三_熊思宇的博客-CSDN博客

C# List 详解四_熊思宇的博客-CSDN博客

C# List 详解六_熊思宇的博客-CSDN博客

C# List 详解七_熊思宇的博客-CSDN博客

26.GetType()    

获取当前实例的 Type。(继承自 Object)

public Type GetType ();

返回
Type
当前实例的准确运行时类型。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };Type type = list1.GetType();Console.ReadKey();}}
}

27.IndexOf(T)    

搜索指定的对象,并返回整个 List<T> 中第一个匹配项的从零开始的索引。

public int IndexOf (T item);

参数
item
T
要在 List<T> 中定位的对象。 对于引用类型,该值可以为 null。

返回
Int32
如果找到,则为整个 item 中 List<T> 第一个匹配项的从零开始的索引;否则为 -1。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };int value = list1.IndexOf(5);Console.WriteLine(value);Console.ReadKey();}}
}

运行:

28.IndexOf(T, Int32)    

搜索指定对象并返回 List<T> 中从指定索引到最后一个元素这部分元素中第一个匹配项的从零开始索引。

public int IndexOf (T item, int index);

参数
item
T
要在 List<T> 中定位的对象。 对于引用类型,该值可以为 null。

index
Int32
从零开始的搜索的起始索引。 空列表中 0(零)为有效值。

返回
Int32
如果在 List<T> 中从 index 到最后一个元素的元素范围内找到 item 的第一个匹配项,则为该项的从零开始的索引;否则为 -1。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };int value = list1.IndexOf(5,3);Console.WriteLine(value);Console.ReadKey();}}
}

运行:

29.IndexOf(T, Int32, Int32)    

搜索指定对象并返回 List<T> 中从指定索引开始并包含指定元素数的这部分元素中第一个匹配项的从零开始索引。

public int IndexOf (T item, int index, int count);

参数
item
T
要在 List<T> 中定位的对象。 对于引用类型,该值可以为 null。

index
Int32
从零开始的搜索的起始索引。 空列表中 0(零)为有效值。

count
Int32
要搜索的部分中的元素数。

返回
Int32
如果在 List<T> 中从 index 开始并包含 count 个元素的元素范围内找到 item 的第一个匹配项,则为该项的从零开始的索引;否则为 -1。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };int value = list1.IndexOf(5,3,2);Console.WriteLine(value);Console.ReadKey();}}
}

运行:

30.Insert(Int32, T)    

将元素插入 List<T> 的指定索引处。

public void Insert (int index, T item);

参数
index
Int32
应插入 item 的从零开始的索引。

item
T
要插入的对象。 对于引用类型,该值可以为 null。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };list1.Insert(1, 2);Console.WriteLine(string.Join("-", list1));Console.ReadKey();}}
}

运行:

31.InsertRange(Int32, IEnumerable<T>)    

将集合中的元素插入 List<T> 的指定索引处。

public void InsertRange (int index, System.Collections.Generic.IEnumerable<T> collection);

参数
index
Int32
应在此处插入新元素的从零开始的索引。

collection
IEnumerable<T>
应将其元素插入到 List<T> 中的集合。 集合自身不能为 null,但它可以包含为 null 的元素(如果类型 T 为引用类型)。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){string[] input = { "1", "2","3" };List<string> dinosaurs = new List<string>();dinosaurs.Add("a");dinosaurs.Add("b");dinosaurs.Add("c");dinosaurs.InsertRange(2, input);Console.WriteLine(string.Join("-", dinosaurs));Console.ReadKey();}}
}

运行:

32.LastIndexOf(T)    

搜索指定对象并返回整个 List<T> 中最后一个匹配项的从零开始索引。

public int LastIndexOf (T item);

参数
item
T
要在 List<T> 中定位的对象。 对于引用类型,该值可以为 null。

返回
Int32
如果在整个 List<T> 中找到 item 的最后一个匹配项,则为该项的从零开始的索引;否则为 -1。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };int index = list1.LastIndexOf(5);Console.WriteLine(index);Console.ReadKey();}}
}

运行:

33.LastIndexOf(T, Int32)    

搜索指定对象并返回 List<T> 中从第一个元素到指定索引这部分元素中最后一个匹配项的从零开始的索引。

public int LastIndexOf (T item, int index);

参数
item
T
要在 List<T> 中定位的对象。 对于引用类型,该值可以为 null。

index
Int32
向后搜索的从零开始的起始索引。

返回
Int32
如果找到,则返回在 List<T> 中从第一个元素到 index 的元素范围内找到 item 的最后一个匹配项的从零开始的索引;否则为 -1。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };int index = list1.LastIndexOf(5,2);Console.WriteLine(index);Console.ReadKey();}}
}

运行:

34.LastIndexOf(T, Int32, Int32)    

搜索指定对象并返回 List<T> 中到指定索引为止包含指定元素数的这部分元素中最后一个匹配项的从零开始索引。

public int LastIndexOf (T item, int index, int count);

参数
item
T
要在 List<T> 中定位的对象。 对于引用类型,该值可以为 null。

index
Int32
向后搜索的从零开始的起始索引。

count
Int32
要搜索的部分中的元素数。

返回
Int32
如果在 List<T> 中到 index 为止包含 count 个元素的这部分元素中找到 item 的最后一个匹配项,则为该项的从零开始的索引;否则为 -1。

案例:

using System;
using System.Collections.Generic;namespace ListTest
{internal class Program{static void Main(string[] args){List<int> list1 = new List<int>() { 1, 3, 5, 5, 6 };int index = list1.LastIndexOf(5,2,2);Console.WriteLine(index);Console.ReadKey();}}
}

运行:

 

第 5 / 7  篇  End

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/6730.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【CAS6.6源码解析】调试Rest API接口

CAS的web层默认是基于webflow实现的&#xff0c;ui和后端是耦合在一起的&#xff0c;做前后端分离调用和调试的时候不太方便。但是好在CAS已经添加了支持Rest API的support模块&#xff0c;添加相应模块即可。 文章目录 添加依赖并重新build效果 添加依赖并重新build 具体添加…

32位Cortex-M4 MCU:LPC54607J256ET180E、LPC54605J512BD100K 180MHz嵌入式微控制器

LPC546xx 32 位微控制器(MCU) 具有丰富的外设集、极低的功耗和增强的调试功能。 LPC546xx MCU系列采用ARM Cortex-M4内核&#xff0c;可提供以太网支持&#xff0c;并设有一个TFT LCD控制器和两个CAN FD模块。LPC546xx MCU旨在提高灵活性和性能可扩展性&#xff0c;可提供高达1…

http-为什么文件上传要转成Base64

# 前言 最近在开发中遇到文件上传采用Base64的方式上传&#xff0c;记得以前刚开始学http上传文件的时候&#xff0c;都是通过content-type为multipart/form-data方式直接上传二进制文件&#xff0c;我们知道都通过网络传输最终只能传输二进制流&#xff0c;所以毫无疑问他们本…

【数据库SQLite】SQLite 约束

约束是在表的数据列上强制执行的规则。这些是用来限制可以插入到表中的数据类型。这确保了数据库中数据的准确性和可靠性。约束可以是列级或表级。列级约束仅适用于列&#xff0c;表级约束被应用到整个表。 常见 SQLite 约束汇总&#xff1a; NOT NULL 约束&#xff1a;确保某…

Vue3 Vite electron 开发桌面程序

Electron是一个跨平台的桌面应用程序开发框架&#xff0c;它允许开发人员使用Web技术&#xff08;如HTML、CSS和JavaScript&#xff09;构建桌面应用程序&#xff0c;这些应用程序可以在Windows、macOS和Linux等操作系统上运行。 Electron的核心是Chromium浏览器内核和Node.js…

CentOS 7.6安装 MongoDB 5.0.2

https://developer.aliyun.com/article/983777 我遇到的问题&#xff1a;如何以集群的方式启动&#xff0c;使用replSet的方式进行启动&#xff1a; 需要在配置文件上加上replSet的信息 port27017 #端口 bind_ip0.0.0.0 #默认是127.0.0.1 dbpath/usr/local/mongodb/data #数据…

ABAP 为N的一个数,在原来基础上浮动在-30~30

需求&#xff1a;为N的一个数&#xff0c;在原来基础上浮动在-30~30 *&---------------------------------------------------------------------* *& Report ZZZZ111 *&---------------------------------------------------------------------* *& 需求&…

【算法基础:搜索与图论】3.4 求最短路算法(Dijkstrabellman-fordspfaFloyd)

文章目录 求最短路算法总览Dijkstra朴素 Dijkstra 算法&#xff08;⭐原理讲解&#xff01;⭐重要&#xff01;&#xff09;&#xff08;用于稠密图&#xff09;例题&#xff1a;849. Dijkstra求最短路 I代码1——使用邻接表代码2——使用邻接矩阵 补充&#xff1a;稠密图和稀疏…

libtorch水下图像增强模型和基准数据集

水下图像增强由于其在海洋工程和水上机器人领域的重要性而备受关注。在过去的几年里,人们提出了许多水下图像增强算法。然而,这些算法主要使用合成数据集或少数选定的真实世界图像进行评估。因此,目前还不清楚这些算法如何处理在野外获取的图像,以及我们如何衡量该领域的进…

npm i babel-plugin-import -D之后报错

替换modules/.bin/XX文件 1.vue-cli-service #!/bin/sh basedir$(dirname "$(echo "$0" | sed -e s,\\,/,g)")case uname in*CYGWIN*) basedircygpath -w "$basedir";; esacif [ -x "$basedir/node" ]; then"$basedir/node"…

【NLP】视觉变压器与卷积神经网络

一、说明 本篇是 变压器因其计算效率和可扩展性而成为NLP的首选模型。在计算机视觉中&#xff0c;卷积神经网络&#xff08;CNN&#xff09;架构仍然占主导地位&#xff0c;但一些研究人员已经尝试将CNN与自我注意相结合。作者尝试将标准变压器直接应用于图像&#xff0c;发现在…

【N32L40X】学习笔记08-定时器的基本定时功能-超时功能

定时器的基本定时功能 该函数库的目的就是在统一的地方配置&#xff0c;将配置的不同项放置在一个结构体内部使用一个枚举来定义一个的别名该库就是基本定时产生超时中断 bsp_time_base.h #ifndef _BSP_BASE_TIME_H_ #define _BSP_BASE_TIME_H_#include <stdint.h> #i…

CAXA中.exb或者.dwg文件保存为PDF

通常CAXAZ中的文件为.exb或者.dwg格式&#xff0c;我们想打印或者保存为PDF文件格式&#xff0c;那么就用一下的方法&#xff1a; CAXA文件如图所示&#xff1a; 框选出你要打印的图纸&#xff01;&#xff01;&#xff01;&#xff01; 我们选择"菜单"->"…

【算法基础:搜索与图论】3.5 求最小生成树算法(PrimKruskal)

文章目录 最小生成树介绍朴素Prim算法算法思路⭐例题&#xff1a;858. Prim算法求最小生成树 Kruskal算法算法思路⭐例题&#xff1a;859. Kruskal算法求最小生成树 最小生成树介绍 最小生成树 有关树的定义 生成子图&#xff1a;生成子图是从原图中选取部分节点以及这些节点…

Keepalived热备、Keepalived+LVS、HAProxy监控及后端服务器健康检查、负载均衡调度器对比

day02 day02KeepAlived高可用集群配置高可用的web集群监控本机80端口&#xff0c;实现主备切换实现原理实施配置高可用、负载均衡的web集群配置高可用、负载均衡HAProxy配置haproxy负载均衡调度器比较LVS&#xff08;Linux Virtual Server&#xff09;NginxHAProxy KeepAlive…

Pytorch个人学习记录总结 08

目录 神经网络-搭建小实战和Sequential的使用 版本1——未用Sequential 版本2——用Sequential 神经网络-搭建小实战和Sequential的使用 torch.nn.Sequential的官方文档地址&#xff0c;模块将按照它们在构造函数中传递的顺序添加。代码实现的是下图&#xff1a; 版本1—…

Linux——crontab使用实例

起因是实验室的主机USB驱动或者供电有问题&#xff0c;部分主机频繁出现USB断连的情况&#xff0c;通过dmesg查看报错 xHCI host controller not responding, assume dead 几经波折终于找到了拯救方案——https://bbs.archlinux.org/viewtopic.php?id236536 但是&#xff01;…

16_LinuxLCD驱动

目录 Framebuffer设备 LCD驱动简析 LCD驱动程序编写 LCD屏幕参数节点信息修改 LCD 屏幕背光节点信息 使能Linux logo显示 设置LCD作为终端控制台 Framebuffer设备 先来回顾一下裸机的时候LCD驱动是怎么编写的,裸机LCD驱动编写流程如下: 1.初始化I.MX6U的eLCDIF控制器,…

Jenkins发送的邮箱中没有带配置的压缩附件

【问题描述】&#xff1a;Jenkins中明明配置了邮箱发送时要带压缩附件&#xff0c;收到的邮箱中却没有附件内容 【问题定位】&#xff1a;压缩附件没有放在Jenkins工作空间下&#xff0c;所以发送的邮件并未发送附件 【解决办法】&#xff1a; 1&#xff09;把压缩附件放到J…

kubernetes持久化存储卷

kubernetes持久化存储卷 kubernetes持久化存储卷一、存储卷介绍二、存储卷的分类三、存储卷的选择四、本地存储卷之emptyDir五、本地存储卷之 hostPath六、网络存储卷之nfs七、PV(持久存储卷)与PVC(持久存储卷声明)7.1 认识pv与pvc7.2 pv与pvc之间的关系7.3 实现nfs类型pv与pvc…