Q:

How to return a value from lambda function

I have this code and it's work correctly,
    private void button1_Click(object sender, EventArgs e)
    {
        var func = new Action<int, int>((a, b) =>
        {
            var sum = a + b;
            MessageBox.Show(sum.ToString());
            //How can I return sum?
        });

        //var result=func(2,3);
        func(2, 3);
    }

How I can change func to return sum variable, I want use function as:
   var result=func(2,3);

A:

An Action represents a method which does not return a value. 
If you want to return a value you need to use a Func<TResult> 
which encapsulates a method that returns a value of the type specified by the TResult parameter.
So in your case you need a Func<T1, T2, TResult> where the arguments are int and so does the return type:
var func = new Func<int, int, int>((a, b) =>
{
    var sum = a + b;
    MessageBox.Show(sum.ToString());
    return sum;
});

var result=func(2,3);

