List的 Select()使用方法 Demo
List的 Select()使用方法
用List存储对象,代码如下:
IList<Student> studentList = new List<Student>();
for(int i=;i<;i++)
{
Student student = new Student();
//赋值
studentList.Add(student);
}
现在需要从studentList中查询符合条件的对象,Student中有个ClassName字段,需要从studentList中查询ClassName为“高一(3)班”的所有学生,一般是这样做的:
foreach(Student student in studentList)
{
if(student.ClassName=="高一(3)班")
{
newList.Add(student);
continue;
}
}
但这种方法比较笨重,请看如下的方法。。
var newList = studentList.Where(s=>s.ClassName=="高一(3)班").ToList();
另一种方法:
List<Student> stu = studentList.FindAll(delegate(Student student)
{
if (student.Name.Equals("高一(3)班"))
{
return true;
}
else
{
return false;
}
});
List的 Select()使用方法 Demo的更多相关文章
- 测试--错误java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=select], {ExactMatcher:fDisplayName=select(com.rjj.demo.DemoApplicationTests)]...
异常这个错误java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=select], {ExactMatche ...
- select ng-change 方法中 拿不到 ng-modal 定义的变量值
在使用angularjs框架的项目中,select 的数据源有两种绑定方式,在option中使用ng-repeat循环绑定,或者在select中使用ng-option 绑定. 无论哪种绑定方式,均要使 ...
- Linq中带有迭代索引的Select扩展方法,为啥知道的人不多呢?
一:背景 昨天在看C#函数式编程这本书的时候,有一处让我干着急,需求是这样: 给多行文字加上数字列表项. 针对这个需求你会如何快捷高效的给每个项目加上数字编号呢? 我看书中是这样实现的,如下代码 pu ...
- jquery的checkbox,radio,select等方法总结
jquery的checkbox,radio,和select是jquery操作的一个难点和重点,很多前端新手对其了解不是很透彻.时间久了不用,我在写的时候有时也难免对某些操作支支吾吾,记不清楚,现在,对 ...
- java 读取Excel文件并数据持久化方法Demo
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util ...
- 插入多行数据和类似 select union 方法
Cite:http://blog.csdn.net/downmoon/article/details/5936706 [ruby] view plaincopyprint? Create table ...
- EF中使用Select new 方法中字段值替换的问题
前提需要替换查询得到的List当中的某个字段的值,替换规则有一个mapping关系 尝试代码 有问题 无法获取任何数据 /// <summary> /// 获取Treegrid的List ...
- Jquery 获取表单值如input,select等方法
1 if($("input[name=item][value='val']").attr('checked')==true) //判断是否已经打勾 name即控件name属性,va ...
- linux c中select使用方法
1.select函数作为定时器使用 it_value.tv_sec = 0; it_value.tv_usec = 100000: select(1,NULL,NULL,NULL,& ...
随机推荐
- js大文件分块上传断点续传demo
文件夹上传:从前端到后端 文件上传是 Web 开发肯定会碰到的问题,而文件夹上传则更加难缠.网上关于文件夹上传的资料多集中在前端,缺少对于后端的关注,然后讲某个后端框架文件上传的文章又不会涉及文件夹. ...
- C的realloc的动态分配扩展和缩小内存
#include <stdio.h> #include <stdlib.h> void out(int *p, int n){ int i; for(i=0;i<n;i+ ...
- docker使(二)—发布node应用镜像和容器
应用在本地是已经ok的了,现在将node应用放进docker容器里面 获取node镜像 docker pull node 编写Dokerfile # 根据node镜像开始创建新的镜像(可以加上:tag ...
- 项目管理、bug管理工具 ---禅道使用流程
使用前描述: 禅道是付费的一款云平台工具,它可以实现项目管理.需求管理.bug提交.bug跟踪.文档管理.bug统计等功能 使用账号.密码:公司提供,登录后基本识别操作流程如下: 1.登录首页-我的地 ...
- 教你用WordPress搭建个人博客
1. 购买VPS,推荐几个供应商: 国外的有:搬瓦工 VirMach vps.net vultr.com 等等 国内的有:阿里云 腾讯云 等等 2. 注册域名:阿里云 腾讯云 3. 下载安装PuTTy ...
- Python字符串转十六进制进制互转
def str_to_hex(s): return ' '.join([hex(ord(c)).replace('0x', '') for c in s]) def hex_to_str(s): ) ...
- linux下anaconda使用教程
安装Anaconda.在命令行输入,下载anaconda.wget https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh. ...
- vue 遇到防盗链 img显示不出来
在index.html中添加: <meta name="referrer" content="no-referrer">
- 创建加载bean的实例
一.创建实例 工程的结构如下图 1.创建接口 public interface Person { public void setName(String name); public String say ...
- 基于CentOS7系统添加自定义脚本服务及参数说明【转】
概述 centos6如果要添加自定义脚本服务只需要把脚本放到/etc/init.d然后授权后用chkconfig添加后就可以管理了,那么centos7又是怎么添加自定义脚本服务呢? CentOS7添加 ...