I am wondering whether I can use the this
keyword inside a C# lambda, although actually I know that I can but I want to make sure that this isn\'t a bad th
While it is correct to use this
in a lambda like that, you just need to be aware that your Repository
object will not be garbage collectable until your Person
object is garbage collectable.
You might want to have a field to cache the result from your lambda, and once it is Lazy filled, release the lambda since you do not need it anymore.
Something like:
private Lazy nameProxy;
private string name;
public string Name
{
get
{
if(name==null)
{
name = nameProxy.Value;
nameProxy = null;
}
return name;
}
}