Reputation: 1704
I have a method that returns a new list (it pertains to a multiple choice answer):
public static List<questionAnswer> GetAnswersWithSelections(this Questions_for_Exam__c question)
{
List<questionAnswer> answers = new List<questionAnswer>();
answers.Add(new questionAnswer() { Ordinal = 1, AnswerText = question.AN1__c, Selected = (bool)question.Option1__c });
...
return answers;
}
If I examine the result of this method - I see the correct data, e.g. Red = False, Green = True, Blue = False
I then try to filter the returned result using the LINQ Where extension method:
List<questionAnswer> CorrectSelections = question.GetAnswersWithSelections();
var tmpA = CorrectSelections.Where(opt => opt.Selected = true);
When I materialise tmpA, 2 things happen:
Any ideas?
Upvotes: 8
Views: 411
Reputation: 7347
your line
opt => opt.Selected = true
needs another equals sign:
opt => opt.Selected == true
Upvotes: 7
Reputation: 81680
You need to use ==
and not =
:
var tmpA = CorrectSelections.Where(opt => opt.Selected == true);
So when you search for condition, you were setting values. This is a common mistake, I fall for it as well :)
Upvotes: 14