C# Paradigms: Side effects on Lists

Viewed 4597

I am trying to evolve my understanding of side effects and how they should be controlled and applied.

In the following List of flights, I want to set a property of each flight satisfying a conditions:

IEnumerable<FlightResults> fResults = getResultsFromProvider();

//Set all non-stop flights description
fResults.Where(flight => flight.NonStop)
        .Select(flight => flight.Description = "Fly Direct!");

In this expression, I have a side effect on my list. From my limited knowledge I know for ex. "LINQ is used for queries only" and "There are only a few operations to lists and assigning or setting values is not one of them" and "lists should be immutable".

  • What is wrong with my LINQ statement above and how should it be changed?
  • Where can I get more information on the fundamental paradigms on the scenario I have described above?
6 Answers
Related