get last element of array c#

71

c# array last element -

int[] array = { 1, 3, 5 };
var lastItem = array[^1]; // 5

c# get last array element -

string[] items = GetAllItems();
string lastItem = items[items.Length - 1];
int arrayLength = array.Length;

ex: c# last item in array -

string lastName = "Abraham Lincoln".Split().Last();

Comments

Submit
0 Comments