Created
May 1, 2025 02:50
-
-
Save renatogroffe/6c1862db09d8d7cca9070312b7be98a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pragma warning disable CS8625 | |
using ConsoleAppNullConditionalAssignment.Models; | |
using System.Runtime.InteropServices; | |
using System.Text.Json; | |
Console.WriteLine("***** Testes com .NET 10 | Null-conditional assignment *****"); | |
Console.WriteLine($"Versao do .NET em uso: {RuntimeInformation | |
.FrameworkDescription} - Ambiente: {Environment.MachineName} - Kernel: {Environment | |
.OSVersion.VersionString}"); | |
var produtos = new List<Produto> | |
{ | |
new Produto() { Id = Guid.NewGuid().ToString(), Nome = "Produto 1", Preco = 10.0}, | |
null, | |
new Produto() { Id = Guid.NewGuid().ToString(), Nome = "Produto 3", Preco = 30.0} | |
}; | |
Console.WriteLine(); | |
Console.WriteLine("Dados antes do reajuste:"); | |
Console.WriteLine(JsonSerializer.Serialize(produtos, | |
new JsonSerializerOptions { WriteIndented = true })); | |
Console.WriteLine(); | |
Console.WriteLine("Aplicando reajustes..."); | |
Console.WriteLine(); | |
foreach (var produto in produtos) | |
{ | |
AplicarReajuste(produto, 10); | |
Console.WriteLine($"Produto: {produto?.Nome}, Preço: {produto?.Preco}"); | |
} | |
static void AplicarReajuste(Produto produto, double percentual) | |
{ | |
produto?.Preco += produto?.Preco * percentual / 100; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment