Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want code for searchig in the list.. which is equivalent to "find name from list where id= 1"
Posted
Comments
Raajkumar.b 4-Feb-14 5:00am    
check this link
http://stackoverflow.com/questions/9854917/how-can-i-find-a-specific-element-in-a-c-sharp-list

There are a lot of ways to do it, but the easiest is probably to use a Linq Method:
Assuming:
C#
public class MyClass
    {
    public int Id { get; set; }
    public string Name { get; set; }
    }
Then:
C#
List<MyClass> list = new List<MyClass>();
...
var matching = list.Where(i => i.Id == 1);
 
Share this answer
 
You can use Linq for this.,
For example -

Suppose you have collection of Person data name as PersonData
C#
List<string> names = (from person in PersonData where person.PersonId == 1 select person.PersonName).ToList(); 


This will return the list of Person Name which id is 1.
Hope this will help you..
 
Share this answer
 
v3

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