Given a very simple expression like:
var x = new Thing();
I was thinking, can you encapsulate new Thing
as a lambda like () => new Thing()
inline, along the lines of:
var x = () => new Thing();
This doesn't compile because I'm trying to assign a delegate to x, not the result of calling it.
But when I try:
var x = (() => new Thing())(); //call my lambda in-line
This also doesn't compile with eror "Method name expected".
So does this imply I cannot declare and use a lambda inline, or just that I don't understand the syntax?
(Note: this is a question about understanding the language, I'm not asking if it's a good idea to do it, only if I can. My example is clearly over-simplified from any real-world use!)