❔ How to make a method becomes available for all form?

SSaltTonic12/18/2022
sorry I'm new at using method. I don't really understand about public method.
BSBin Starjs12/18/2022
the public modifiers just makes your member accessible through anywhere, but to obtain it, you need a reference to that member, e.g passing it as argument of a method or make it static to make the reference available anywhere or store it in a field to make the reference available inside that instance.

Also you mix things up by mentioning "method" and "list" so the question is vague
SSaltTonic12/18/2022
so when im making a method i have to type static after the public?
BSBin Starjs12/18/2022
first of all, what do you want to do? and what are you expecting? i do not understand completely of your intention
SSaltTonic12/18/2022
im trying to make highscore list for a game that i made. So when i lost, it will show you the highscore in the next form. My friend told me that i should just make a public method and call it in another form. Yet i dont know how to do it.
BSBin Starjs12/18/2022
is this a winform app?
SSaltTonic12/18/2022
yeah
BSBin Starjs12/18/2022
i see. honestly i am not an expert in a GUI application development but yeah if you want to call a method that can be accessed from anywhere and anytime, you can make the method a static method, but like i said, this may not be the best solution as i am not an experienced person in desktop development
BSBin Starjs12/18/2022
however, marking a method as static will make it unable to access instance members (all members, fields or methods that are not marked with static within the class)
SSaltTonic12/18/2022
so should i just remove the static?
BSBin Starjs12/18/2022
it depends. it seems you are a bit lost. I suggest for you to study more C# fundamentals such as what is the static keyword, how it works etc
SSaltTonic12/18/2022
alright imma try to study more :when:
BBuddy12/18/2022
$static
MMODiX12/18/2022
In C#, static allows you to have members (classes, methods, etc) that are not tied to any particular instance and are therefore always, globally, accessible. When applying static members, take the following considerations:
• If there are to be multiple instances of a class, do not use static
• If you need to track state, do not use static
• If you are going to have multi threaded workflows, do not use static unless you're aware of the caveats

static is best used for stateless methods, extension methods/classes and in areas where you understand the pros/cons. Read more here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/static
AAccord12/19/2022
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.