C
C#2y ago
Down

❔ filtering searches

So i have this field
private static List<SearchGroup> _searches = new List<SearchGroup>
{
new SearchGroup("Recent Searches")
{
new Search { Id = 1, Location = "New York", CheckIn = DateTime.Now, CheckOut = DateTime.Now },
new Search { Id = 2, Location = "Los Angeles", CheckIn = DateTime.Now, CheckOut = DateTime.Now }
}
};
private static List<SearchGroup> _searches = new List<SearchGroup>
{
new SearchGroup("Recent Searches")
{
new Search { Id = 1, Location = "New York", CheckIn = DateTime.Now, CheckOut = DateTime.Now },
new Search { Id = 2, Location = "Los Angeles", CheckIn = DateTime.Now, CheckOut = DateTime.Now }
}
};
and i have a method public static IEnumerable<SearchGroup> GetSearches(string filter = null) that gets filter as parameter and needs to return new List<SearchGroup> but only with Searches thats Location property starts with filter value tried doing it with Linq and i dont know how to make it this is my attempt:
public static IEnumerable<SearchGroup> GetSearches(string filter = null)
{
return _searches
.Where(outer => outer
.Where(inner => inner.Location.StartsWith(filter))
.Select(item => item));
}
public static IEnumerable<SearchGroup> GetSearches(string filter = null)
{
return _searches
.Where(outer => outer
.Where(inner => inner.Location.StartsWith(filter))
.Select(item => item));
}
2 Replies
Down
DownOP2y ago
also this is SearchGroup class
internal class SearchGroup : List<Search>
{
public string Title { get; set; }

public SearchGroup(string title)
{
Title = title;
}
}
internal class SearchGroup : List<Search>
{
public string Title { get; set; }

public SearchGroup(string title)
{
Title = title;
}
}
and this is Search class
internal class Search
{
public int Id { get; set; }
public string Location { get; set; }
public DateTime CheckIn { get; set; }
public DateTime CheckOut { get; set; }
}
internal class Search
{
public int Id { get; set; }
public string Location { get; set; }
public DateTime CheckIn { get; set; }
public DateTime CheckOut { get; set; }
}
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server