It is necessary to check the division by zero inside the lambda bends!

double Div(double a, double b) => a / b;

  • Easier to make a normal method. Code without frills read and understood better. - Bulson
  • I know, but the task is to do just that - Mykola Tolkachov
  • four
    make a check is one thing, but what do you need to get in the end? throw? double, like, at 0 divides normally (Infinity eventually will be) - Andrey NOP
  • one
    You do not have the lambda expression in question. Your K. O. - VladD
  • one
    This is called the "Method Compressed before Expression" (expression-bodied method) - Andrey NOP

1 answer 1

For example, you can do it with a ternary operator, like this:

 double Div(double a, double b) => b != 0 ? a / b : 0; 

If you have the second parameter ( b ) zero, it will return zero. Returned zero is just an example. Operator ?: Is a ternary operator. You can read here: Operator?: (Reference book on C #)

  • It is, at least, strange to return zero if the divider is zero, although it wants the vehicle for us to remain a mystery ... - Andrey NOP
  • @ Andrew that he did not want an answer, he arranged it: D - Ev_Hyper