Добавить в корзинуПозвонить
Найти в Дзене
Машинное обучение

🖥 Что выведет код

? public decimal CalculateTotal(Order order) { decimal total = 0; if (order != null) { if (order.Items != null) { foreach (var item in order.Items) { if (item != null) { if (item.IsActive) { if (item.Price > 0) { if (item.Quantity > 0) { total += item.Price * item.Quantity; } } } } } } if (order.Customer != null) { if (order.Customer.IsVip) { total = total * 0.9m; } } } return total; } Как бы ты почистил этот код? A - Заменить вложенные if на guard clauses B - Использовать LINQ для фильтрации и суммы C - Вынести скидку VIP в отдельный метод D - Все варианты выше t.me/csharp_ci

🖥 Что выведет код?

public decimal CalculateTotal(Order order)

{

decimal total = 0;

if (order != null)

{

if (order.Items != null)

{

foreach (var item in order.Items)

{

if (item != null)

{

if (item.IsActive)

{

if (item.Price > 0)

{

if (item.Quantity > 0)

{

total += item.Price * item.Quantity;

}

}

}

}

}

}

if (order.Customer != null)

{

if (order.Customer.IsVip)

{

total = total * 0.9m;

}

}

}

return total;

}

Как бы ты почистил этот код?

A - Заменить вложенные if на guard clauses

B - Использовать LINQ для фильтрации и суммы

C - Вынести скидку VIP в отдельный метод

D - Все варианты выше

t.me/csharp_ci