Question

when creating new Func<> what is the value of Target property?

Im creating this Func object in constructor of class A which has base class B. In B I compare objects like this :

func.Target != this

which is true..

And I dont simply understand why it is not false..

thanks

Was it helpful?

Solution 2

issue fixed.

I used a local variable in function lambda expression. It should be a calss variable obviously..

OTHER TIPS

Maybe this can help:

    static void Main(string[] args)
    {
        Program p = new Program();
        p.MainImpl();
    }

    public void MainImpl() {
        Func<string> f = null;
        Program _this = this;
        f = () => { 
               Console.WriteLine(this == f.Target); 
               Console.WriteLine(this == _this); return null; 
        };
        //Prints "False True"
        f();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top