With C# 6's expression-bodied members, I can write:
public string FullName => $"{_firstName} {_lastName}";
And I can write:
static void Print(string message) => Console.WriteLine(message);
In the first instance, the expression returns something. In the second, it doesn't.
What's happening here for it to determine how to 'act' without the need for any additional syntax? Or is it simply a case of it looking at the method signature during compile time?
I'm not a big fan of leaving things to 'just work' without knowing what's happening.
$"..."
is just a short version ofString.Format(...)
which undoubtfully returns astring
. – Cauleyvoid
, isn´t it? There is no further compiler-decision on this. I don´t see your problem. – Cauleyreturn
keyword. So the compiler appears to have made that decision. – Hierophantstatic string Print(string message) => message;
? This is just another way of writingAction<T>
andFunc<T>
– Dolley