I am learning lambda expression and delegates.While i try to execute the following ,I am getting error at the line which is marked bold line. (Error : Operator '+=' cannot be applied to operands of type 'Test.MessageDelegate' and 'lambda expression').Help me to handle lambda expression.
namespace Test
{
public delegate void MessageDelegate(string title,object sender,EventArgs e);
class Program
{
static event MessageDelegate logEvent;
static void Main(string[] args)
{
logEvent = new MessageDelegate(OnLog);
logEvent("title",Program.logEvent,EventArgs.Empty);
logEvent += (src, e) => { OnLog("Some",src, e); };
Console.ReadKey(true);
}
static void OnLog(string title, object sender, EventArgs e)
{
if (logEvent != null)
{
Console.WriteLine("title={0}", title);
Console.WriteLine("sender={0}", sender);
Console.WriteLine("arguments={0}",e.GetType());
}
}
}
}