In C#, we can refactor the above code block to use LINQ and make it more readable. Here's the refactored code:
main.cs150 chars4 lines
In this code, instead of using a foreach loop, we're using LINQ's Select to iterate over each item in subarticlecontainers, and project it to a new value. We're also using Min to get the minimum price of all subarticles in each container. Finally, we're using ToList to create a new list of the projected values.
This code is more concise and more declarative than the original foreach loop, which makes it easier to read and understand.
gistlibby LogSnag