C# 4.List

comboBox使用的下拉框

Lsit 列表

1 创建List对象

List<string> list = new List<string>();

2 Add给list 添加元素

list.Add("吃饭");

list.Add("睡觉");

list.Add("打豆豆");

3 删除一个元素

list.Remove("吃饭"); // 删除指定的元素

list.RemoveAt(0);// 删除指定索引值的元素

4 修改

list0 = "打铁";

5 查询 通过索引值查询

MessageBox.Show(list0);

6遍历所有的 item 就是数组的元素

foreach (string item in list)

{

MessageBox.Show(item);

}

comboBox2.DataSource = list; //3 下拉框的DataSource属性。添加数据源

作业

向集合List添加10个学生对象 自己添加属性 ;下拉框显示学生姓名

private void button1_Click(object sender, EventArgs e)

{

List<string> list1 = new List<string>();

for (int i = 0; i < 10; i++)

{

list1.Add("老" + i);

}

comboBox3.DataSource = list1;

}

//1 向集合list添加10个学生对象 自己添加一些

public class Student

{

public string Name { get; set; }

public string Age { get; set; }

}

相关推荐
goehou7 小时前
让 AI 替我操作这台电脑,先把手能伸多远定下来
windows·自动化·权限管理·ai agent
公子小六8 小时前
基于.NET的Windows窗体编程之WinForms数据持久化(1)
windows·microsoft·c#·.net·winforms
三雷科技9 小时前
第6章第4节:自定义分词器
开发语言·c#
zhanghaha131411 小时前
C# 系列教程_12 字符串 string 保姆级系统教程(面向新手,大量示例 + 原理讲解)
开发语言·数据库·c#
2601_967987371 天前
安装 Redis 或 Redis Stack
linux·windows·redis·macos·安装
Coder_Shenshen1 天前
罗克韦尔ACD工程归档离线变量树解析
算法·c#
xbzb1 天前
自定义 yum 软件源:Linux 上 createrepo,Windows 上纯 Python 也能造
linux·运维·windows·python·yum·createrepo
武雄(小星Ai)1 天前
Ollama报llama-server binary not found排坑实录:服务活着引擎没了
人工智能·windows·大模型·ollama·排坑
Severus_black1 天前
【C++初阶】list使用及相关实现,思路顺滑流畅!
c语言·数据结构·c++·stl·list
寂寞的船1 天前
【Unity知识速递】第10期 Unity GC 零分配实战:从 UnityEngine.Pool 到手动 GC 控制的全链路优化
jvm·unity·c#·游戏引擎·lucene