This fails
string temp = () => {return \"test\";};
with the error
Cannot convert lambda expression to type \'str
An anonymous method can return a value using a func delegate. Here is an example where I have shown how to return a value using an anonymous method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Func del = delegate (int x)
{
return x * x;
};
int p= del(4);
Console.WriteLine(p);
Console.ReadLine();
}
}
}