If I have a class like this:
public class SomeClass
{
public Action<string> SomeAction { get; set; }
public SomeClass()
{
SomeAction = GetSomeAnonymousMethod();
}
private Action<string> GetSomeAnonymousMethod()
{
return (text) =>
{
Console.WriteLine(text);
};
}
}
What happens when I make a new instance of SomeClass
? My impression is that the constructor simply calls GetSomeAnonymousMethod()
, which returns a new delegate instance (that only contains a reference to the compiler-generated backing method for the anonymous method), and assigns it to the SomeAction
property.
Can someone confirm, or is something more sinister happening?