Domanda

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

È stato utile?

Soluzione 2

issue fixed.

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

Altri suggerimenti

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();
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top