Why does C# not allow me to call a void method as part of the return statement?

Because it’s simply the way the language is defined.

A method can use return statements to return control to its caller.
In a method returning void, return statements cannot specify an
expression.
In a method returning non-void, return statements must
include an expression that computes the return value.

It’s an arbitrary decision (presumably made for compatibility with ANSI C and its other descendants), and other languages do things differently.

For example, in Python, all functions return a value. If you execute a return statement without a value, or let control reach the end of the function, then it’s just like you had written return None.

In contrast, Pascal limits the terminology of function to subprograms that have a return value; if you don’t want to return anything, you use a procedure instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)