Reputation: 579
I have a string[]
with the following values in it:
x
y
z
I am trying to remove the string z, based on the fact that is the last element in the array, and replace it with w. Is this possible?
Upvotes: 1
Views: 192
Reputation: 252
Possible. If your array has fix 3 item.
Array starts at 0 index, so z
is at the 2 index.
arr[2] = "w";
Upvotes: 0
Reputation: 61349
You can use Length
to find the last index, and just assign it to replace it:
myArray[myArray.Length - 1] = "w";
Note the -1 since Length
is not 0-indexed
Upvotes: 8