15
Reply

How does this Lambda expression work?

S

S

Sep 9 2012 4:06 PM
4.8k
Hi

Given this code example:-

public readonly Dictionary<Type, Func<Object>> providers = new Dictionary<Type, Func<Object>>();

public void Bind<T>(T instance)
{
        providers[typeof(T)] = () => instance;
}

My question is why is a Lambda expression used for the assignment of the parameter "instance" to providers[typeof(T)]?

I tried assigning the "instance" parameter on its own but got a cast\conversion error.

Regards

Steven



Answers (15)