thestrayed thestrayed - 1 year ago 100
C# Question

Calculate IEnumerable<decimal> with decimal without using for-loop

I was given a discount percentage as a decimal and I have

as a list of prices. I want to calculate discount price for each one in linq.

IEnumerable<decimal> prices = new IEnumerable<decimal>() { 100, 200, 300};
decimal discountPercentage = 20;

Shoot me some idea, I would love to try anything.

Answer Source

Hope this helps

IEnumerable<decimal> prices = new List<decimal>() { 100, 200, 300};
decimal discountPercentage = 20;
var discounted = prices.Select(x=>x-x/100*discountPercentage).ToList();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download