C
C#11mo 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
canton711mo ago
PrintPerson is underlined in red. Have a look at the error there 😉
McCormick
McCormick11mo ago
But I did.
No description
canton7
canton711mo ago
The error's slightly cryptic. The problem is the ; at the end of the PrintPerson line
Angius
Angius11mo ago
No description
McCormick
McCormick11mo ago
Oh lol, thank you so much.
canton7
canton711mo 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
Angius11mo 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
MODiX11mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server