Is there a better/quicker way to check if from a list of objects at least one object has a certain property?
@{if (Model.StockPositions.Count(x => x.Kaufpreis != 0) > 0) {
This will not stop after the first positive hit, will it?
Is there a better/quicker way to check if from a list of objects at least one object has a certain property?
@{if (Model.StockPositions.Count(x => x.Kaufpreis != 0) > 0) {
This will not stop after the first positive hit, will it?
Well an alternative would be:
@{if (Model.StockPositions.Any(x => x.Kaufpreis != 0) {
If you're interested in the performance difference between Count()
and Any()
, you might find this answer helpful.