© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
14 replies
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;
}
/*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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ problem with understanding delegates and generics
C#CC# / help
3y ago
Need help understanding lambda statements and delegates
C#CC# / help
4y ago
Delegates
C#CC# / help
2y ago
❔ Delegates
C#CC# / help
3y ago