A
A
Alexveto2020-06-02 10:38:09
C++ / C#
Alexveto, 2020-06-02 10:38:09

Why can't object methods be called through the delegate's Target property?

If there is a delegate that has been assigned some non-static object method:

SomeClass someObject = new SomeClass();
SomeDelegate someDelegate = someObject.SomeNonStaticMethod;

Then this output will give true
Console.WriteLine(someDelegate.Target == someObject);

Then why can't you do that?
someObject.SomeMethod();
someDelegate.Target.SomeMethod(); // а вот так почему-то нельзя

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-06-02
@Alexveto

Bring Targetto its type SomeClass, and then it will be possible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question