I am running Visual Studio 2015 Enterprise, .NET 4.6, and I wrote some code that relies on Delegates being static. I ran the exact code from this question, but I get "false":
static void Main(string[] args)
{
Action<string> actionMethod = s => { Console.WriteLine("My Name is " + s); };
// Always false
Console.WriteLine(actionMethod.Method.IsStatic);
Console.Read();
}
Is this a bug? Or does C# not guarantee that lambdas without nonlocal dependencies are made static?
Is there a workaround to determine if a lambda/delegate has nonlocal dependencies? My goal is to know if a lambda caught it's enclosing variables / uses a closure.