本文介绍了如何根据条件显示列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
This is my code
public List<PersonRepository> PersonListwithLamdaExpressionsFind()
{
var listData = PersonListwithcityName().Any(fa=>fa.Age > = 24 && fa.Age <= 30);
Console.WriteLine("The following code retrieves the persons who are having age between 24 and 30");
foreach(var item in listData)
{
Console.WriteLine(item.PersonID + "\t" + item.Name + "\t"+ item.Address + "\t" + item.Age +"\t" + item.Salary + "\t"+ Colors.ForeColor(item.CityName));
}
return listData;
}
我的查询是想显示年龄介于20到30之间的记录,因为我已经使用lambda编写了这段代码表达但是它在foreach显示错误
所以请建议我怎么写这个?
My query is i want to display the records that who's age between 20 and 30 for that i have written this code by using lambda expression but it is displaying error at foreach
so please suggest me how to write this?
推荐答案
var listData = PersonListwithcityName().where(fa=>fa.Age > = 24 && fa.Age <= 30);
注意:
Any() - 它确定集合中的任何元素是否与某个条件匹配。它返回 True 或 False 。这不是您需要的。请尝试一个以上。
Note:
Any()-It determines if any element in a collection matches a certain condition.It returns True or False.Which is not what you need.Try above one.
这篇关于如何根据条件显示列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!