Reputation: 79
I need to select a list which is not contains grade 2 and grade 8 . Now all the items with grade 2 also selects. Please see below is my code
var subjectList = printViewModel.GetSubjects().Where(p => p.Grade != "2" || p.Grade != "8");
PrintTemplateViewModel class
public class PrintTemplateViewModel
{
public List<SubjectsViewModel> lstSubjectsViewModel { get; set; }
public List<SubjectsViewModel> GetSubjects()
{
return lstSubjectsViewModel;
}
}
public class SubjectsViewModel
{
public string Grade { get; set; }
}
Upvotes: 0
Views: 416
Reputation: 12437
The "OR" is working fine. It is your logic that is not working :D
use &&
because you want to check both values are true.
Upvotes: 0
Reputation: 70652
You want &&
, not ||
. No matter what the string value, it's always going to either not be "2" or not be "8". It can't be both at once! :)
Upvotes: 5