method with object lists error
Hey all, new to C# and am trying to learn some basics, so im starting by making a trivia game, however im running into an error and i'm not sure why, any help would be greatly appreciated!
54 Replies
going to add another part later that goes through the lists and randomly picks and writes a questions
What is the error?
I'm not sure to be honest
Can you send the whole code snippet
one moment
oop sorry
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/Or $paste more like
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
And the whole thing. My suspicion is you have something like a variable inside of a namespace, a semicolon after an
if()
, something like thatBlazeBin - tkfiymhsvnwo
A tool for sharing your source code with the world!
would you also like the Question class?
BlazeBin - bhyzkojmfeuu
A tool for sharing your source code with the world!
well there it is if needed
Seems... fine
Does it build?
nope
Even from the CLI, with
dotnet build
?let me try
nope
I understant the null pointer erros
just not the namespace stuff
You cant use public inside your function i guess
Oooooh
Good catch!
Yeah, local variables don't have access modifiers
They're local
And i recommend u to use .add to ur list
Oh, interesting, thanks
I don't recommend
.Add
at all, it would make the whole thing unnecessarily verbosei got rid of the publics and it works thanks!
I'd even shorten it even more with target-type new and collection expressions
im thinking about changing it to an array once i confirm all the questions im going to use
Or even better, by loading the questions from a json file
yeah no clue what that is lol
was thinking about this
but still inexperienced with json
and just wanted to get a working thing
oh interesting, so you dont need to define it as a new list?
It is a new list
[] does that for u
It already has the type information in one place
oh, i see
It knows it's a list, and a list of things
would it be the same for an array?
or similar with an array syntax
Should be
Angius
REPL Result: Success
Compile: 370.544ms | Execution: 66.123ms | React with ❌ to remove this embed.
ye
what is the "record" i havent seen that before
It's basically a shorthand for creating a class + constructor + properties + other stuff
neat, thanks I appreciate the help
Here's what this record compiles into
So would
one moment let me write this out lol
be the same as the record
would be closer
But yes
ah yea, i havent really gone into the whole get set finish whatnots
Properties
Alright well thanks for your help I really appreciate
Anytime :Ok: