C
C#12mo 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
Thinker12mo ago
Well, only one file may contain code outside of a class. You probably have multiple files like that?
soujanya
soujanyaOP12mo ago
No description
soujanya
soujanyaOP12mo ago
here first i deleted program.cs i thought that might be a problem but it didnt fix my issue
Thinker
Thinker12mo ago
What do first.cs and second.cs contain?
soujanya
soujanyaOP12mo ago
this basic code
No description
ThatDaniel
ThatDaniel12mo 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
soujanyaOP12mo ago
means should i write code in old format or what
ThatDaniel
ThatDaniel12mo 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
soujanyaOP12mo ago
ok thanks
Want results from more Discord servers?
Add your server