❔ Action and Callback
We are passing a function named "callback" as if it were a variable as a parameter, and then we are calling it as if we had previously called the function by saying "callback(age, ...)". How does this process work, how do the codes work step by step?
6 Replies
It just kinda does. In C#, like in many other languages, you can pass pointers to functions around
This is no different
Whether you pass an anonymous function (
Action<>
, Func<>
, delegate
) or an actual method
And you don't pass it "as if it was a variable" because it is, in fact, stored in that variable
Or at least the reference to itAngius
REPL Result: Success
Console Output
Compile: 645.382ms | Execution: 78.123ms | React with ❌ to remove this embed.
When the function is invoked, it happened like this, right? And lastly, the relevant function became this:
Instead of callback(age, name, isActive) being at runtime, it became
displayInfo(age, name, isActive)
Like in case of any other parameter, yes
Thank you a lot, I understood
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.