C#C
C#3y ago
Gerald

❔ 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.
/*This is an example of "can I use a Delegate this way as well"*/

private int Health, MagicPoints, ExperiencePoints;

 private delegate int StatBars(int Hp, int Mp, int Xp);

private void Start()
{
 PassExample(Health);
}
private void PassExample(StatBars myStats)
{
myStats(Health, MagicPoints, ExperiencePoints);
}

private void Health(int hp, int mp, int xp)
{
 hp = Health = 25;
mp = MagicPoints = 50;
xp = ExperiencePoints = 0;
}

When writing it out, it looks a tad improper but I am unaware of if this is acceptable.
Was this page helpful?