35 Replies
Having some issues with this code
I’m getting and out of index error when executing
And i am not sure how to create an instance of the class with the strongly type class Jedi as a type
Please paste your code as this your code is unreadable, because it misses indentation.
$paste
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
$paste
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
pasted here
yes ik sry facepalm
This code won't even compile
The pasted version is just as bad
my bad
please have a look at this one
BlazeBin - ysyvcuznypfv
A tool for sharing your source code with the world!
@amio @Kouhai @Buddy
Well
What do you think this means?
number of items in the array?
Well, the array size doesn't change does it?
So it always holds the same amount of elements no matter if it's actually populated or not.
Image this view of the array with 5 elements
var arr = new string[5]
if we examine the array it's basically
[null, null, null, null, null]
We then push
["my_string", null, null, null, null]
The array length doesn't changehmm makes sense
so i could just return the number of items that have been pushed
Exactly, you also should add some safe guards in both
Push
and Pop
yes i noticed that
what about this part?
Well, your implementation isn't generic
This isn't generic
what do I need to modify?
What do you think should be modified?
If you want to allow T to be pushed and popped
hmmmmm
i dont see it
Do you know how generics work in C#?
not entirely
I don't mean how it internally works, just how to make a class/method generic
i kinda forgot ngl
been a while
string[] to T?
Well, that won't really work
Because string[] is an array of strings
hmm could you please point where the error is?
Let's step back a bit
In this example what value(s) can be set to baz's Value?
an int?
Yup, exactly
ohhh i get your point
but how does this work with my array?
In a generic class/method T is just a type, you can do whatever you want with
So something like
T[]
is possiblethanks!
GOAT