Reputation: 93
I don't know how I can return a list with all the soundfragments that contain the string in the titel.
fragmenten = new List<Geluidsfragment>();
public List<Geluidsfragment> GetFragment(String p)
{
fragmenten.IndexOf(p);
}
I hope you guys can help me with this problem.
Upvotes: 1
Views: 99
Reputation: 1689
LINQ is the best option available with lambda expression.
You can use it like:-
fragmenten.Where(s => s.Title.Contains(title)).ToList()
Upvotes: 0
Reputation: 460288
You can use List.FindAll
:
List<Geluidsfragment> result = fragmenten.FindAll(f => f.Title.Contains(title));
Another option is LINQ's Enumerable.Where
with Enumerable.ToList
:
result = fragmenten.Where(f => f.Title.Contains(title)).ToList();
Upvotes: 2
Reputation: 9947
yourlist.Where(x => x.property.Contains(value)).ToList();
Upvotes: 0
Reputation: 40990
Try this
List<Geluidsfragment> requiredList = fragmenten.Where(x => x.Title.Contains(p)).ToList();
Upvotes: 1
Reputation: 56716
Assuming you have a string Title
property:
return fragmenten.Where(f => f.Title.Contains(p)).ToList();
You might need to add this to the using section of your file:
using System.Linq;
Upvotes: 2