Wednesday, July 13, 2016

C# this == null

How to make NullFun.Method to write "true" to Console?

public class NullFun
{
    public void Method ()
    {
        Console.WriteLine(this == null);
    }
}

Read below for the answer.



class Program
{
    delegate void Method();
 
    static void Main(string[] args)
    {
        typeof(NullFun).GetMethod("Method").CreateDelegate(typeof(Method), null).DynamicInvoke();
    }
}

No comments: