Trailing Zeros
I'm currently implementing / Simulating a list and have created a Sort method, which implementes bubble sort. For some reason, every time I expand the size of my internal array, I have trailing zeros and have no idea how to get rid of them. I have a feeling that the problem might be the way I compare the values.
Does anyone know how I can get rid of the zeros at the end?

65 Replies
do you have an example that demonstrates the issue you're seeing?
arrays don't have a capacity like lists, the size is always equal to the number of elements in the array
so if you resize an array, the new slots will contain the default value for the type (in this case, 0)
I just realised that the problem might be how I implemented the insert method.
I'm currently trying something brb
nvm
This is how it looks like

This is how the add method looks likee

to me it looks like you're not properly using your
_count throughout your class
you're adding 6 items which causes your code to end up with an 8 element backing array
the zeroes aren't really "in" the collection, they're just unused elements in the array that your class shouldn't be exposing or touchingUnknown User•5w ago
Message Not Public
Sign In & Join Server To View
Yeah, but I can't use my _count, because it just keeps track of my index and doesn't really show the actual size of my array
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View

Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
Tried but it pastes as .txt even when I use the C# format
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
TeBeCo
REPL Result: Success
Result: int
Compile: 145.046ms | Execution: 13.775ms | React with ❌ to remove this embed.
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
Yeah
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
But for classes the value is null, so I can simply use another method to exclude all the null values
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
oh ok
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
No sure, is it because there aren't any values? just empty spaces
Like nothing
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
Well I know value types are copies of the original and references point to the memory
Is that correct?
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
Had C, but since it was only last year we didn't learn that much. The main programming language is C#
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
Na, we didn't get to that point
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
I'm stuck
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
I just realized that I can't really understand anything under the term "memory"
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
0
So if no value is inserted in the array, then you have zeros, correct?
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
In terms of defaults values though, correct?
TeBeCo
REPL Result: Success
Result: bool
Compile: 304.118ms | Execution: 16.089ms | React with ❌ to remove this embed.
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
That's why it's immutable?
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
I'll watch the video, thanks for helping
Very appreciated
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
I just realized it doesn't display the "trailing zeros" for string
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
But does it make any difference in this case, whether i use _count or Count
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
Count returns _count
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
No
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
We haven't even learnt that
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
The Interface forced me to implement both
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
So I don't need both?
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
It doesn't now
I removed the second one and there's no error
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
public IEnumerator<T> GetEnumerator()
{
return new MyListEnumerator<T>(_myList);
}
Like this?
How do you send the codes like this
or do you mean this
public class MyList<T> : IEnumerable<T>?
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
@TeBeCo Thanks for your help
Unknown User•5w ago
Message Not Public
Sign In & Join Server To View
If you have no further questions, please use /close to mark the forum thread as answered