C#数据类型:List

List(T是一种数据类型,比如int、string、GameObject等)是一个非常有用的集合类型,它位于System.Collections.Generic命名空间下。它可以动态地调整大小,能够方便地添加、删除和访问元素。

cs 复制代码
//创建List
List<int> intList = new List<int>();
List<string> stringList = new List<string>();

//添加元素
stringList.Add("Hello");
stringList.Add("World");

//插入元素
stringList.Insert(1, "Good");

//访问元素
string secondstr = stringList[1];

//获取元素数量
int count = stringList.Count;

//删除元素
stringList.Remove("World");

//删除指定索引位置的元素
stringList.RemoveAt(1); 

//清空List元素
stringList.Clear();

//查找元素
int index = stringList.IndexOf("World");

//检查list是否包含元素
List<float> floatList = new List<float>() {1.0f, 2.0f, 3.0f};
bool containsTwo = floatList.Contains(2.0f);

//排序List中的元素
List<int> intList = new List<int>() {3, 1, 2};
intList.Sort();
相关推荐
Scout-leaf3 天前
WPF新手村教程(三)—— 路由事件
c#·wpf
用户298698530143 天前
程序员效率工具:Spire.Doc如何助你一键搞定Word表格排版
后端·c#·.net
mudtools4 天前
搭建一套.net下能落地的飞书考勤系统
后端·c#·.net
玩泥巴的5 天前
搭建一套.net下能落地的飞书考勤系统
c#·.net·二次开发·飞书
唐宋元明清21885 天前
.NET 本地Db数据库-技术方案选型
windows·c#
郑州光合科技余经理5 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
lindexi5 天前
dotnet DirectX 通过可等待交换链降低输入渲染延迟
c#·directx·d2d·direct2d·vortice
feifeigo1235 天前
matlab画图工具
开发语言·matlab
dustcell.5 天前
haproxy七层代理
java·开发语言·前端
norlan_jame5 天前
C-PHY与D-PHY差异
c语言·开发语言