✅ classes giving me an error for no reason
i made this little code using a tutorial im watching, everything was the same except i wanted to try using "book1.title.Length); method. but for some reason its giving me an error which is on the file.
please help. thanks
25 Replies
Can you post your
C#.csproj
?<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>C_</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
That's fine. Is your
Book.cs
in the same C# folder as your Program.cs
?idk if this helps
but it is yeah
$vscode
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
Hmm, not quite the one I was after. There are some gotchas for setting up vs code with C# IIRC -- Visual Studio is a lot easier
What command are you running to try and build?
on terminal i use "dotnet run" to run my programs
could it be something with extensions?
Can you zip your project up and post it here?
There's something I'm missing, but I can't think what it is. What you have should be fine
uhhsorry but... how do i convert files into zip? i have never done that before >.<
lemme try
Right click on your C# folder -> Send To -> Zipped (compressed) folder
its giving me a virus threat thing for some reason
oh wait
i got it
OK, it doesn't work here either. Let me find out why...
Your Book.cs is empty
what does that mean?
The file Book.cs literally has nothing in it
I think you forgot to save it
...
uh oh
i mean... i got the thing im looking for but this time i got a warning
(im so dumb 💀)
Yeah. That's expected. You've got Nullable Reference Types enabled
If you're just starting, set
<Nullable>disable</Nullable>
in your .csproj
You'll appreciate that stuff when you're a bit more experienced. Right now it's just a distractiondoes nullables change anything? a friend told me that i could add ! next to the things to disable them
It tells the compiler to give you warnings in some cases
Yes you can use
!
to silence warnings in some cases... But it's better to properly learn about it so that you can use it effectively
and if you're only just starting, you've got more important things to learni pasted the link my friend gave me so i could read it later but yeah, it seems pretty advanced thing for now
thanks for the help though! (i really have to not forget saving files i always forget them)
No worries!