Guest User

Guest User

  • Tech Writer
  • 357
  • 120.1k

How does this Lambda expression work?

Sep 9 2012 4:06 PM
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)