Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
This is my code
C#
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;

       }

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?
Posted
Updated 30-May-14 1:20am
v4
Comments
Animesh Datta 30-May-14 7:31am    
What error you are getting ?

1 solution

Please try as below. :)

var listData = PersonListwithcityName().where(fa=>fa.Age > = 24 && fa.Age <= 30);


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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900