C
C#7mo ago
Chroma

✅ methods

Can a method be something else apart from static ?
13 Replies
333fred
333fred7mo ago
It can be non-static IE, by removing the static keyword
Chroma
ChromaOP7mo ago
static means that the method belongs to the Program class right?
333fred
333fred7mo ago
No Static means you do not need to invoke the method on an instance All methods inside Program belong to Program, the question is whether you need an instance of Program to invoke them
Angius
Angius7mo ago
I can have a
public class Skibidi
{
public static int Toilet()
{
return 69;
}
}
public class Skibidi
{
public static int Toilet()
{
return 69;
}
}
Toilet is a static method, yes, but it belongs to the Skibidi class, not the Program class
Chroma
ChromaOP7mo ago
and public i assume means that it can be invoked everywhere in the program or other .cs files?
333fred
333fred7mo ago
Not just in the program, but also anything that references it For example, Console.WriteLine is a public method in a public class, that you're getting from .NET
Chroma
ChromaOP7mo ago
Ok i hope i will understand these one day i still mess up pretty badly static void for example with public static but its something normal its easier than C
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Mango
Mango7mo ago
I'm removing ur purple
Jimmacle
Jimmacle7mo ago
the pattern is essentially [visibility] [static or nothing] <return type> where void is a return type that means it doesn't return any data there are some other keywords you can throw in the mix but they would just be confusing to bring up now
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Denis
Denis7mo ago
I guess foo bar is out of fashion nowadays...

Did you find this page helpful?