C
C#11mo ago
Ewan

✅ It says it must have a return type but idk how, help please!

No description
13 Replies
Angius
Angius11mo ago
Well, any method has to have a return type See how itemInfo() says it returns a string?
Ewan
EwanOP11mo ago
yes?
SG97
SG9711mo ago
are you trying to create a constructor?
Angius
Angius11mo ago
Every method has to declare what it returns
SG97
SG9711mo ago
for Menu
Angius
Angius11mo ago
If it returns nothing, it can be void
Ewan
EwanOP11mo ago
yes
Angius
Angius11mo ago
But it has to be some declaration $structure
MODiX
MODiX11mo ago
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;

int LocalMethod(string param) { return 3; }
}
}
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;

int LocalMethod(string param) { return 3; }
}
}
Ewan
EwanOP11mo ago
hmmm ok then
Angius
Angius11mo ago
If it's a constructor, then it should have the exact name as the class
SG97
SG9711mo ago
Constructors - C# programming guide - C#
A constructor in C# is called when a class or struct is created. Use constructors to set defaults, limit instantiation, and write flexible, easy-to-read code.
Ewan
EwanOP11mo ago
OHH same name ok nvm got it thanks!

Did you find this page helpful?