67 Replies
im tryna add names and ages from all the objects
Can you tell us what the error at the red line says? :)
into a dictionary
can you try guess what this error means?
not gonna lie, this code makes 0 sense
i don't even know
you start somewhere, Jimmacle 😄
💀 word
right but some extra info is needed to figure out what your end goal is, because it's not clear from the code itself
Human.name
would try to access a field or property name
which is static on HumanIf you're trying to use a dictionary, why can't you guess at what the error means?
🤔
but name is a non-static instance field
name
isn't staticThat's their point.
it's public string
so you have to either use
this.name
or, take it from an instance of HumanAdd(name, age)
just remove "Human"
when u specify Human.age
you're referencing the static field age
Can't do that eithr.
Need an instance.
we are in the ctor :)
but hes running that from the constructor
I'll see myself into my corner of shame.
he is in the instance.
ye
so do i make them static
you don't want them static
nameAndAge should be
Dictionary<string, int>
you might want them public
no
they r
huh
where are
nameAndAge
defined?
ah i see nowyeah the next point is that the dictionary expects a Human as a key and a Human as a value. You probably want Name as a key and age as a value
i did that
Dictionary<Human, Human> nameAndAge
there you should add an keyvalue pair of humans and humans and im pretty sure you dont want it
and what u got?0
cause of my first line
im meant to get 3 tho
huh'
why not? you called new Human() three times
idek
apparently its cause
im overpopulating my constructor
do you understand what the constructor is for?
whats the purpose of
nameAndAge
dictionary?not really
nothing, just testing things
constructor is an method that is called on the object initialization
the constructor is run whenever a new object Human is created
yeah ik
for each
new Human()
, you call your constructor once on itoh wait
wait
wait
😄
still didn't work
i removed the loop
you're right
but why is it still writing 0
because you're calling it before you define each human
you're calling
objectCount++
on constructor, which is called on new Human
The Dark Realm's No. 2 - Hazel
REPL Result: Success
Console Output
Compile: 769.700ms | Execution: 67.870ms | React with ❌ to remove this embed.
what you mean? are u talking about the dictionary or the first writeline?
you first write the count and then add 3 humans :)
code in a method runs from the top down, you have to do the stuff you want to run first at the top
how to run this code snippet?
This is still wrong.
$eval
To compile C# code in Discord, use
!eval
Example:
Please don't try breaking the REPL service. Also, remember to do so in #bot-spam!is it?
Oh chiz, it was made static; okay 😄
I stand corected.
Hazel are you sleepy?
Yeah
It always was
😭
😄
Back to my corner of shame.
Byeeeee lol
maybe we should direct this person to writing the code in a more logical way instead of whatever this is turning into
cypherpotato
REPL Result: Success
Console Output
Compile: 763.247ms | Execution: 113.162ms | React with ❌ to remove this embed.
@Ahmed see the 3 in the end?
is that what you're expecting?
i know why it wasn't loading in
it's cause i had console.readline();
💀
yes
ye im an idiot
i fixed it
thank you everyone
!close
Closed!
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.