71.7k views
4 votes
Omitting the return type is allowed only for functions with an expression body. For functions with a block body that return a value, you have to specify the return type and write the return statements explicitly.

a) True
b) False

1 Answer

6 votes

Final answer:

True. Omitting the return type is allowed only for functions with an expression body. For functions with a block body that return a value, you have to specify the return type and write the return statements explicitly.

Step-by-step explanation:

True. Omitting the return type is allowed only for functions with an expression body. For example, in C# you can have a function with an expression body like this: int Multiply(int a, int b) => a * b; The function has a return type (int) but it is omitted from the function signature. On the other hand, functions with a block body that return a value require the return type to be specified and the return statements to be written explicitly. For example, int Add(int a, int b) { return a + b; }.

User Michael Chudinov
by
7.6k points