I have List<Book> Books
public class Book
{
public string Name { get; set; }
public string Author { get; set; }
public string Category { get; set; }
public string Language { get; set; }
public DateTime Publication_date { get; set; }
public string ISBN { get; set; }
}
tried this, but it only work if all parameters matched
foreach (var item in Books)
{
if ((!string.IsNullOrEmpty(name) && item.Name == name)
&& (!string.IsNullOrEmpty(author) && item.Author == author)
&& (!string.IsNullOrEmpty(category) && item.Category == category)
&& (!string.IsNullOrEmpty(language) && item.Language == language)
&& (Publication_date.HasValue && item.Publication_date == Publication_date)
&& (!string.IsNullOrEmpty(ISBN) && item.ISBN == ISBN))
{
Console.WriteLine(item);
}
}
how to make filter by one or more parameters? like if i enter only "name" and "Language" it will print me the book where both parameters a matched (if string is null or empty then parameter should be skipped)
Thanks)