C
C#•8mo ago
Yuno šŸ‘

āœ… Why am I getting these errors

😃
No description
48 Replies
Buddy
Buddy•8mo ago
C# is project based; not file based. $vscode
MODiX
MODiX•8mo ago
Follow the instructions here on getting started with DevKit for C# in VSCode: https://code.visualstudio.com/docs/csharp/get-started
Get started with C# and .NET in Visual Studio Code
Getting Started with C# and .NET Development in Visual Studio Code
Buddy
Buddy•8mo ago
If you are a beginner I'd recommend Visual Studio Community 2022 VSCode is a lot of manual work and configuration to make it work well
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Yeah so it seems I already installed the extensions and the dotnet thing
Buddy
Buddy•8mo ago
Yes, but you have not opened the folder containing the csproj / sln
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
No description
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Damn I need an account too
Buddy
Buddy•8mo ago
It's optional
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Ohhh Okay that's good
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
No description
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
I was able to set everything up
Buddy
Buddy•8mo ago
Great!
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Now I just need to copy my code here and see if it works now
Buddy
Buddy•8mo ago
You don't need Program and static void main when you have top-level statements, you also need to remove the namespace. As they are generated underneath
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
No description
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Weird Wdym by namespace
Buddy
Buddy•8mo ago
Its not weird
Buddy
Buddy•8mo ago
No description
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
It is to me 😃
Buddy
Buddy•8mo ago
It requires 2 arguments You only have one Foo("hello", "bar");
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
What am I doing with the first one that Im not doing with the second one? šŸ˜€ Wait
Buddy
Buddy•8mo ago
What is the argument here?
No description
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
No description
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Yeah Just saw that šŸ˜€
Buddy
Buddy•8mo ago
And check how have you declared the constructor
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Is there a problem there?
Buddy
Buddy•8mo ago
read it Read this code out loud for yourself It expects a title and ..?
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Oh yeah
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
No description
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
I had already changed this I just got confused
Angius
Angius•8mo ago
šŸŽ‰
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
I thought there was something else I was missing too
Buddy
Buddy•8mo ago
Correct. As you had declared it to only accept 2 arguments of type string.
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
I get it now 😃 Thanks a lot
Buddy
Buddy•8mo ago
Anytime, note that you don't need to use class program and static void main, you can just call your code directly at the top of the file (under using declarations) via top-level statements.
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
I don't know what top level statements are šŸ˜…
Angius
Angius•8mo ago
Console.WriteLine("Hello World");
Console.WriteLine("Hello World");
Instead of
namespace MyApp;

public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
namespace MyApp;

public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
Buddy
Buddy•8mo ago
using System;

Console.WriteLine("hello");
MyBook book = new MyBook("tewt");

class MyBook
{
public string Title { get; set; }

public MyBook(string title)
{
Title = title;
}
}
using System;

Console.WriteLine("hello");
MyBook book = new MyBook("tewt");

class MyBook
{
public string Title { get; set; }

public MyBook(string title)
{
Title = title;
}
}
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
So all of this is useless and I can just get rid of it?
No description
Buddy
Buddy•8mo ago
Yes. Except the code inside main, yes. as zzzz said
Angius
Angius•8mo ago
Not useless per se, the compiler just generates it for you
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Okay I see There's no harm to leaving it there though?
Buddy
Buddy•8mo ago
No Just easier to use top-level statements, that's all.
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Alright fair enough I definitely have a lot to learn about c# šŸ˜€ I don't know anything
Yuno šŸ‘
Yuno šŸ‘OP•8mo ago
Anyway thanks guys You taught me a lot in a short time
Buddy
Buddy•8mo ago
$close
MODiX
MODiX•8mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?