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

Did you find this page helpful?