I have the following LINQ Select which does not work.
Data.Select(d => d.Value.IsDirty = true); //-- Not working
My longer workaround does.
foreach (var d in Data)
d.Value.IsDirty = true;
Why does my first code not work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Select()returns anIEnumerable<…>, which has the ability to iterate over the input and invoke the code in question, but doesn’t actually do so until you enumerate it in some manner:or
However, given that they perform side effects (obviously the intent here), both of the above are bad karma. Don’t use them. Your original
foreachis the only sensible choice.