C
C#12mo ago
Nguynnn :>

can somebody explain to me the func of static void?

I need help.... :>
5 Replies
Omnissiah
Omnissiah12mo ago
could you be a little more specific? func as in Func<>?
Buddy
Buddy12mo ago
$static
MODiX
MODiX12mo ago
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
Buddy
Buddy12mo ago
void means nothing, meaning it does not return a value. so if you'd replace the return datatype from void to int then it indicates that you want to return an integer (a whole number) instead of returning no value.
SteveHarper スティーブン
If you create a class called Person, and Person has a property called Name, you would instantiate a new Person like this. Person bob = new(); bob.Name="Bob";. If you had a method in it called public string GetPlanet(), it would have to return a string, and you would call it like this: string? planet = bob.GetPlanet(); If you have a static method, however, you would NOT use bob to call it. You would use Person to call it. If, for example, the Person class had a static method called public static int GetTheNumber1(), then you would call it like this: int number = Person.GetTheNumber1(); and it would ALWAYS return the same thing no matter how many times you made a new Person. Also, it would NOT be tied to any particular person. If you did bob.GetTheNumber1(); you would get a compilation error. (CS0176 Member 'Person.GetTheNumber1()' cannot be accessed with an instance reference; qualify it with a type name instead)
Want results from more Discord servers?
Add your server