❔ Understanding Delegates
Hi there. I'm a bit new to delegates. There are a couple things that I would like to straighten out. For one, I don't exactly know what they are, but do I know how they can be used. I know how to create one, but I do not know their limitations nor how to subscribe with the question mark (?).
Also, I have another thought about the use case of a Delegate, but I'm not sure if the way I'm thinking about it can be used this way.
When writing it out, it looks a tad improper but I am unaware of if this is acceptable.
6 Replies
A delegate, in this context, is nothing more than a type for a method. Be it a regular method, or a lambda
and
are basically the same
In the second case, though, you get proper naming for the parameters, better IDE hints, and it's easier to see what's the return type and what's the param type
I also recommend to use func, action. It is way easier to understand imo
So to reiterate, writing this down would look like this instead? :
Would this be right? And I can also expand upon it with what I have in my previous example?
HP => Hp.Health
this won't work, HP
and Hp
are different variables
And you never call PassExample()
are you aiming for like a getter of the hp amount in form of a delegate?
kinda like this
think of delegates as interfaces with one method
this is very close to what a delegate does internally
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.