C
C#ā€¢3mo ago
Yuno šŸ‘

āœ… Why am I getting these errors

šŸ˜ƒ
No description
48 Replies
Buddy
Buddyā€¢3mo ago
C# is project based; not file based. $vscode
MODiX
MODiXā€¢3mo 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ā€¢3mo 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 šŸ‘ā€¢3mo ago
Yeah so it seems I already installed the extensions and the dotnet thing
Buddy
Buddyā€¢3mo ago
Yes, but you have not opened the folder containing the csproj / sln
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
No description
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Damn I need an account too
Buddy
Buddyā€¢3mo ago
It's optional
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Ohhh Okay that's good
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
No description
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
I was able to set everything up
Buddy
Buddyā€¢3mo ago
Great!
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Now I just need to copy my code here and see if it works now
Buddy
Buddyā€¢3mo 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 šŸ‘ā€¢3mo ago
No description
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Weird Wdym by namespace
Buddy
Buddyā€¢3mo ago
Its not weird
Buddy
Buddyā€¢3mo ago
No description
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
It is to me šŸ˜ƒ
Buddy
Buddyā€¢3mo ago
It requires 2 arguments You only have one Foo("hello", "bar");
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
What am I doing with the first one that Im not doing with the second one? šŸ˜€ Wait
Buddy
Buddyā€¢3mo ago
What is the argument here?
No description
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
No description
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Yeah Just saw that šŸ˜€
Buddy
Buddyā€¢3mo ago
And check how have you declared the constructor
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Is there a problem there?
Buddy
Buddyā€¢3mo ago
read it Read this code out loud for yourself It expects a title and ..?
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Oh yeah
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
No description
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
I had already changed this I just got confused
Angius
Angiusā€¢3mo ago
šŸŽ‰
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
I thought there was something else I was missing too
Buddy
Buddyā€¢3mo ago
Correct. As you had declared it to only accept 2 arguments of type string.
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
I get it now šŸ˜ƒ Thanks a lot
Buddy
Buddyā€¢3mo 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 šŸ‘ā€¢3mo ago
I don't know what top level statements are šŸ˜…
Angius
Angiusā€¢3mo 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ā€¢3mo 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 šŸ‘ā€¢3mo ago
So all of this is useless and I can just get rid of it?
No description
Buddy
Buddyā€¢3mo ago
Yes. Except the code inside main, yes. as zzzz said
Angius
Angiusā€¢3mo ago
Not useless per se, the compiler just generates it for you
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Okay I see There's no harm to leaving it there though?
Buddy
Buddyā€¢3mo ago
No Just easier to use top-level statements, that's all.
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Alright fair enough I definitely have a lot to learn about c# šŸ˜€ I don't know anything
Yuno šŸ‘
Yuno šŸ‘ā€¢3mo ago
Anyway thanks guys You taught me a lot in a short time
Buddy
Buddyā€¢3mo ago
$close
MODiX
MODiXā€¢3mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server