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?
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 :)
your line
opt => opt.Selected = true
needs another equals sign:
opt => opt.Selected == true
You want opt.Selected == true
. You have a single =
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With