C
C#2y ago
gododo

✅ array

how can i do this?
18 Replies
gododo
gododoOP2y ago
i did this drawing as an example since im not good with words basically i gotta remove stuff from the array so like with the var delete it basically removes values inside that array in the end i should still have 7 places available but inside those 5 i deleted there shouldnt be anything left
Servator
Servator2y ago
You can use Range operator
MODiX
MODiX2y ago
Toshiya Joshima#3472
REPL Result: Success
var numbers = new[]
{
1, 2, 3, 4, 5
};

var wantedIndex = numbers[^5];

wantedIndex
var numbers = new[]
{
1, 2, 3, 4, 5
};

var wantedIndex = numbers[^5];

wantedIndex
Result: int
1
1
Compile: 458.835ms | Execution: 56.721ms | React with ❌ to remove this embed.
gododo
gododoOP2y ago
im confused how did result 1 come up
gododo
gododoOP2y ago
and what does this mean
Servator
Servator2y ago
^ means from End It starts to count from End From end 5th element
gododo
gododoOP2y ago
oh i see
Servator
Servator2y ago
which is 1
gododo
gododoOP2y ago
so the other numbers are gone right but not like the spaces
Servator
Servator2y ago
It's not returnign the value itself It returns index
gododo
gododoOP2y ago
oh
mtreit
mtreit2y ago
arrays are immutable. You can't delete elements from them without making new arrays.
gododo
gododoOP2y ago
oh alright so when i do an array that has like 10 different values, its size will always be 10 no matter what ?
mtreit
mtreit2y ago
You can use Array.Resize to change the size of an existing array. That method will internally make a new array with the desired size and copy the data from the old array into it. Generally, however, if you want an array-like instance that you can grow and shrink, you should use a List<T> and not an array.
gododo
gododoOP2y ago
alright ty
Servator
Servator2y ago
You can close this thread with /close
gododo
gododoOP2y ago
i gotta do something first when i dont need it ill close it
Accord
Accord2y ago
Closed!
Want results from more Discord servers?
Add your server