The problem here isThat's You've defined an anonymous method which returns a string but is trying to assign it directly to a string. It's an expression which when invoked produces astringIt's not directly a string. It needs to is assigned to a compatible delegate type. The easiest choice is func<string>func<string> temp = () = {return ' test ';}; This can is doneinchOne line by a bit of casting orusingTheDelegateconstructor to establish the type of the lambda followed by an invocation.String temp = ((func<string>) (() = {return "Test";})) (); string temp = new Func<string> (() = {return "test"; }) (); Note:both samples could is shorted to the expression form which lacks the {return ... } Func <string> temp = () = "test"; string temp = ((func<string>) (() = (() = "test")); string temp = new FUNC&L T;string> (() = "test") ();
C # anonymous method return value assignment to variable