leora
leora

Reputation: 196459

find inside array of objects

i have a objectA

 public class objectA
 {
     public int Id;
     public string Name;
 }

i have a list of objectA

List<objectA> list;

i want to find in the list any objectA with Id = 10;

is there linq syntax for this or do i simply have to write a loop here.

Upvotes: 1

Views: 142

Answers (2)

Joe Lloyd
Joe Lloyd

Reputation: 574

To return all objects with an Id of ten, you'll need:

list.Where(o => o.Id = 10)

Upvotes: 1

Joel Coehoorn
Joel Coehoorn

Reputation: 415705

list.Where(o => o.Id == 10);

Remember: you can chain those method calls, or you can use the IEnumerable returned here for things like databinding.

Upvotes: 3

Related Questions