当前位置: 首页 > news >正文

C# 常用集合的使用

本文用到的知识点为ArrayList
实现需求:在班级集合添加学生信息

画面组态

创建Form窗体,并在窗体添加DataGridView控件

代码编写

在Form窗体load事件中添加下面代码

dataGridView1.Columns.Clear();dataGridView1.Columns.Add("Name", "姓名");dataGridView1.Columns.Add( "Sex","性别");dataGridView1.Columns.Add("Birthday","出生日期");ArrayList P_list_StudentInfo = new ArrayList();string[] P_str_students, p_str_info;string P_str_student = "";//创建Arraylist集合,并添加数据P_list_StudentInfo.Add("小王 男 1989-12-2");P_list_StudentInfo.Add("小钱 男 1989-12-22");P_list_StudentInfo.Add("小赵 男 1992-12-21");P_list_StudentInfo.Add("小孙 女 1995-12-23");P_list_StudentInfo.Add("小刘 男 1997-12-22");//遍历Arraylist集合,将数据合并成字符串。foreach (string P_stu_info in P_list_StudentInfo){P_str_student += P_stu_info + ",";}//使用字符串拆分,将并存储在一个字符串数组中P_str_students = P_str_student.Split(',');dataGridView1.Rows.Add(5);//DataGridview控件添加5行,Row是行,Columns是列for(int i=0; i< P_str_students.Length-1;i++)//遍历字符串数组{p_str_info = P_str_students[i].Split(' ');dataGridView1.Rows[i].Cells[0].Value = p_str_info[0];dataGridView1.Rows[i].Cells[1].Value = p_str_info[1];dataGridView1.Rows[i].Cells[2].Value = p_str_info[2];}

tips

1、DataGridview控件添加列方法。

           dataGridView1.Columns.Clear();dataGridView1.Columns.Add("Name", "姓名");dataGridView1.Columns.Add( "Sex","性别");dataGridView1.Columns.Add("Birthday","出生日期");

2、DataGridview控件添加行方法

 dataGridView1.Rows.Add(5);//DataGridview控件添加5行,Row是行,Columns是列dataGridView1.Rows[1].Cells[0].Value//代表第一行第一列的值

3、Split用法。
通过基于一个或多个分隔符拆分输入字符串来创建子字符串数组

string phrase = "The quick brown fox jumps over the lazy dog.";
string[] words = phrase.Split(' ');foreach (var word in words)
{Console.WriteLine($"<{word}>");
}
//output:Thequickbrownfoxjumpsoverthelazydog.

在这里插入图片描述

http://www.dtcms.com/a/565772.html

相关文章:

  • 合肥市建设网官方网站公司微网站怎么做的
  • 网站服务器的费用如何在网站后台删除栏目
  • 3.4 Lua代码中的文件操作
  • 高盛西湖智谷引进高科技企业 聚集产业高质量发展
  • 行业网站建设公司自己怎么做一个企业官网
  • Hercules
  • Python从入门到精通:(2)Python 核心进阶教程从数据结构到面向对象
  • 普洱专业企业网站建设制作书签图片大全简单漂亮
  • 违法网站开发者网页在线短网址生成器
  • HWiNFO下载和安装图文教程(附安装包,非常详细)
  • 【Unity基础详解】(6)Unity核心:物理系统
  • LLM基础·Huggingface使用教程
  • 新手学做网站百度云做塑胶网站需要什么
  • Oracle故障处理|【实战笔记】一次“删不掉的表”:全局临时表 ORA-14452 故障复盘
  • npm install core-js不成功
  • 【论文精读】SimDA:用于高效视频生成的简单扩散适配器
  • 许昌哪个网站做苗木百度网站介绍显示图片
  • CLIP:打破模态壁垒,重塑AI理解世界的方式
  • firewall-cmd 防火墙操作技巧详解(适用于 CentOS / RHEL 系列)
  • 视频融合平台EasyCVR结合视频智能分析技术构建高空抛物智能监控系统,守护“头顶上的安全”
  • python node 网站开发广东省建设工程执业中心网站
  • ModelEngine智能体全流程体验评测:从创建到部署的深度实践
  • 青岛北京网站建设公司哪家好一万元小型办厂设备
  • PHP:一种强大的服务器端脚本语言
  • 深入了解linux网络—— 守护进程
  • JIS A 5908-2022 刨花板检测
  • 新余网站网站建设网站建设岗位有哪些
  • C# 基于halcon的视觉工作流-章56-彩图转云图
  • 住房城乡建设部办公厅网站网址大全导航
  • 做一个网站的费用构成wordpress 表格 链接地址