C
C#13mo ago
McCormick

✅ Method creation

I can't understand what he doesn't like if I wrote it right. Please help.
No description
8 Replies
canton7
canton713mo ago
PrintPerson is underlined in red. Have a look at the error there 😉
McCormick
McCormickOP13mo ago
But I did.
No description
canton7
canton713mo ago
The error's slightly cryptic. The problem is the ; at the end of the PrintPerson line
Angius
Angius13mo ago
No description
McCormick
McCormickOP13mo ago
Oh lol, thank you so much.
canton7
canton713mo ago
So you've declared a method without a body (the compiler sees void PrintPerson(string name, int age); as the method definition). The compiler complains that the method has no body, then treats the block afterwards as a bit of normal code, and complains about the unknown name variable
Angius
Angius13mo ago
What you have here is akin to
void PrintPerson(string name, int age)
{

}

{
Console.WriteLine($"Name: {name} Age: {age}");
}
void PrintPerson(string name, int age)
{

}

{
Console.WriteLine($"Name: {name} Age: {age}");
}
MODiX
MODiX13mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server