❔ 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
cap5lut14mo 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
MODiX14mo 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
Accord14mo 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
More Posts
✅ Windows Joystick APIWhat's the recommended Windows API to use for Joystick/Gamepad input these days if one needs backgro❔ why is there a comma in the [] when working in a multidimensional arrayim fairly advanced with c# but had no use to use multidimensional arrays for what im working on so i❔ LINQ expressions with "pipeline" patternBasically I need to process an AST in multiple steps to generate a LINQ expression from it. To that ❔ MAUI blazor windows handle URIHey so, I've been trying to get MAUI blazor to run as a single instance to handle custom URIs, with ✅ Tutorial For Desktop App Development???I've looked all over google and I cannot find a tutorial to teach me how to build a desktop applicat❔ can anyone help me figure out hashauth?Trying to edit debug settings but they're locked behind hashauth, anyone know how it works? https:/❔ Razor pages asp-validation-for="MyProperty " vs asp-validation-summary="All"I am working on a simple registration form using a Razor page, and having trouble getting a message ❔ ✅ Register instance of List as singletonThis feels like a dumb question, but I'm trying to keep a singleton instance of a List that can be a❔ Octokit can find the git hub repo but not the latest repository```csharp using Microsoft.AspNetCore.Mvc; using MooMooBotWebAPI.TokenAuthentication; using System.Ne❔ Dusplicate type names: using namespace vs changing the type names.Lets say you have 2 models with the same name like `MyApp.Customers.Orders` and `MyApp.Employees.Ord