Here is a really short and simple example of how multiply all elements from a list with C#. The bad way and the good way.

The bad way to multiply items from a list with C#

There is actually nothing bad about it. It is just not sexy and doesn’t use LINQ. But to be honest with you, it is probably the most instinctive way to write it.

So like I said, why not using the power of LINQ? This code will give you the same result.

The good way to multiply numbers from a list

Now let’s say you need to do more than just multiplying. Something like A² * B² * C², then you could still use the power of LINQ by doing like this:

Happy coding! 🙂