C
C#6mo ago
soujanya

error cs8802 vs code ide

how can I run c# code it says "Only one compilation unit can have top-level statements" what to do please help
No description
9 Replies
Thinker
Thinker6mo ago
Well, only one file may contain code outside of a class. You probably have multiple files like that?
soujanya
soujanya6mo ago
No description
soujanya
soujanya6mo ago
here first i deleted program.cs i thought that might be a problem but it didnt fix my issue
Thinker
Thinker6mo ago
What do first.cs and second.cs contain?
soujanya
soujanya6mo ago
this basic code
No description
ThatDaniel
ThatDaniel6mo ago
you can only lay code out like that in one file (generally the Program.cs) all other code needs to be in methods inside classes/structs
soujanya
soujanya6mo ago
means should i write code in old format or what
ThatDaniel
ThatDaniel6mo ago
e.g
//Inside Program.cs file:

var script = new Script1();
script.Thing();

//Inside Script1.cs file:

public class Script1
{
public void Thing()
{
//code here
}
}
//Inside Program.cs file:

var script = new Script1();
script.Thing();

//Inside Script1.cs file:

public class Script1
{
public void Thing()
{
//code here
}
}
soujanya
soujanya6mo ago
ok thanks
Want results from more Discord servers?
Add your server
More Posts