To what extent is it recommended, or even good practice, to use expression-bodied ?
I know that expression-bodied allow properties, methods, operators, and other function members to have bodies defined using lambda expressions ( =>
) rather than instruction blocks, which helps reduce the amount of code and gives a clearer view of the expressions.
Does this practice impact performance or is it only "visual", leaving the code leaner?
Example below:
No 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;
}