❔ top level statements must precede namespace and typer declerations

I am new to C# and am using vs code. I am learning about "classes" and am getting this error
5 Replies
𝔎𝔦𝔰𝔰_𝔐𝔶_𝔄𝔵𝔢
here is my code: class wizard { public string name; public string favouritespell; public int spellslots; public float experience; } wizard wizard1 = new wizard(); wizard1.name = "Parry Hopper"; wizard1.favouritespell = "spell1"; wizard1.spellslots = 2; wizard1.experience = 0f;
cap5lut
cap5lut2y ago
move the class declaration under the rest of the code
// this is ur class declaration (a class is a type)
class wizard
{
public string name;
public string favouritespell;
public int spellslots;
public float experience;
}

// these are your top level statements
wizard wizard1 = new wizard();
wizard1.name = "Parry Hopper";
wizard1.favouritespell = "spell1";
wizard1.spellslots = 2;
wizard1.experience = 0f;
// this is ur class declaration (a class is a type)
class wizard
{
public string name;
public string favouritespell;
public int spellslots;
public float experience;
}

// these are your top level statements
wizard wizard1 = new wizard();
wizard1.name = "Parry Hopper";
wizard1.favouritespell = "spell1";
wizard1.spellslots = 2;
wizard1.experience = 0f;
(also its better to use $code blocks to show code)
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
𝔎𝔦𝔰𝔰_𝔐𝔶_𝔄𝔵𝔢
thanks that worked
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server