5
The extent to which it is recommended, or even good practice to use Expression-bodied?
I know that the Expression-bodied allow properties, methods, operators and other function members to have defined bodies using expressions lambda (=>
) rather than instruction blocks, which helps to reduce the amount of code and gives a clearer view on expressions.
This practice impacts performance or is only "visual", leaving the code more streamlined?
Example below:
Without Expression-bodied:
public class Item
{
public int Quantidade { get; set; }
public double Preco { get; set; }
public double Total
{
get
{
return Quantidade * Preco;
}
}
}
With Expression-bodied:
public class Item
{
public int Quantidade { get; set; }
public double Preco { get; set; }
public double Total => Quantidade * Preco;
}
Thanks for the explanation! I was using quite rightly for helping to decrease the number of lines and also make the code simpler, in my opinion. I just wanted to clear those doubts right there, thank you!!
– SUR1C4T3