© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
15 replies
Zee

❔ is there a way for a method to have interchangeable parameter?

is there a way for a method to have interchangeable parameter depending on when I call it?

so I have this method
       public void DrankHealthBoost(Health_Boost potion)
        {
            health += 1;
        }
       public void DrankHealthBoost(Health_Boost potion)
        {
            health += 1;
        }

this method has a parameter of type Health_Boost and when I call it I do this

    private void CollectHealthPot(Health_Boost potion, Player pl)
        {
            pl.DrankHealthBoost(potion);

        }
    private void CollectHealthPot(Health_Boost potion, Player pl)
        {
            pl.DrankHealthBoost(potion);

        }

is there a way I can change the DrankHealthBoost(Health_Boost potion) parameter so I can do something like this

        private void CollectHealthPot(Shop potion, Player pl)
        {
            pl.DrankHealthBoost(potion);

        }
        private void CollectHealthPot(Shop potion, Player pl)
        {
            pl.DrankHealthBoost(potion);

        }


so have the parameter to be of type class shop
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

[Unity] Is there a way to have a ContextMenu give an arguement to a method?
C#CC# / help
16mo ago
Is there some way that I can have a method in a Dictionary?
C#CC# / help
4y ago
Is there a way to ensure a function can't modify a parameter?
C#CC# / help
3y ago
How to set a default method for an optional parameter in a method.
C#CC# / help
2y ago