关于List的操作
来源:互联网 发布:java method的反射 编辑:程序博客网 时间:2024/06/10 07:39
一 List的添加和遍历和删除和条件查找
二代码
using System.Collections.Generic;using System.Linq;class Program{ static void Main(string[] args) { int i = 0; List<DEPT> list = new List<DEPT>(); list.Add(new DEPT() { DeptId = 1, DeptName = "外科", DoctorNum = 18 });//用list添加科室 list.Add(new DEPT() { DeptId = 1, DeptName = "肾内科", DoctorNum = 6, Desc = "肾内科描述" }); list.Add(new DEPT() { DeptId = 1, DeptName = "眼科", DoctorNum = 3, Desc = "眼科描述" }); System.Console.WriteLine("for循环遍历结果:"); for (i = 0; i < list.Count; i++) { System.Console.WriteLine("科室id = " + list[i].DeptId + " 医生人数 = " + list[i].DoctorNum + " 科室描述: " + list[i].Desc); } System.Console.WriteLine("找出医生数目大于6的科室:"); //System.Func<DEPT,bool> 表示函数的参数1个且类型为DEPT,返回值为bool类型 IEnumerable<DEPT> ienumerable = list.Where((dept) => { return dept.DoctorNum > 6; });//要添加这个引用 using System.Linq; 才可以使用Where(); foreach (DEPT Dept in ienumerable) { System.Console.WriteLine("科室id = " + Dept.DeptId + " 医生人数 = " + Dept.DoctorNum + " 科室描述: " + Dept.Desc); } System.Console.WriteLine("删除医生数目大于3的科室:"); list.RemoveAll((dept) => { return dept.DoctorNum>3; }); System.Console.WriteLine("foreach遍历结果:"); foreach (DEPT ObjDept in list) { System.Console.WriteLine("科室id = " + ObjDept.DeptId + " 医生人数 = " + ObjDept.DoctorNum + " 科室描述: " + ObjDept.Desc); } System.Console.ReadLine(); }}class DEPT//科室类 { public int DeptId { get; set; }//科室id public string DeptName { get; set; }//科室名字 public string Desc { get; set; }//描述信息 public int DoctorNum { get; set; }//医生人数 }
0 0
- 关于List的操作
- 关于List的操作
- 关于List的一些操作
- 关于List比较好玩的操作
- 关于c++ list容器的操作摸索
- 关于Redis中的list常见的操作
- 【ITOO】---关于List的remove操作
- Struts2标签——关于List<Object[]>的操作
- 关于List Control控件实现翻页操作的基本代码
- 关于List操作排序工具,collection.sort的原理
- 关于bindingSource的datasouce和list操作------刷新问题
- 读阿里巴巴开发规范关于list集合操作的问题
- 安卓 关于list数据操作的设计思路
- 对List的操作
- List的特殊操作
- python的list操作
- python的list操作
- Redis的List操作
- Android数据存储与IO
- [LeetCode]38. Count and Say
- csr_matrix计算tf
- Django 官方文档write your first Django app --5
- python中的 @ 修饰符
- 关于List的操作
- 【Linux Is Not Unix】centos安装jdk感受
- SSM整合案例
- 对象
- Android性能优化-过度绘制解决方案
- 程序员面试金典: 9.10 扩展性与存储限制 10.5如果要设计一个网络爬虫程序,该怎么样避免陷入无限循环。
- 一个好的学习文档下载服务器
- HTML<input>标签的name和id属性区别
- 蓝牙pbap协议源码解析