C
C#5mo ago
eid

how to write method outside the main method in the program class?

in the non program-main style , how i can write method outside the main method in the program class?
4 Replies
Angius
Angius5mo ago
Just do
Console.WriteLine(Text());

string Text()
{
return "yap yap yap";
}
Console.WriteLine(Text());

string Text()
{
return "yap yap yap";
}
Only limitation is that methods and classes have to be placed after the top-level code
eid
eidOP5mo ago
thanks
Pobiega
Pobiega5mo ago
Worth noting that they technically are still inside Main
SleepWellPupper
SleepWellPupper5mo ago
All methods before the first type are local functions. Everything after (including) the first type declaration are members of the generated Program class. So basically you can do
statements
methods
statements
classes
//no statements beyond this point
methods
classes
statements
methods
statements
classes
//no statements beyond this point
methods
classes
fixed, thanks
Want results from more Discord servers?
Add your server