C # Last List List Item

This is probably a very simple question, I want to access the last element:

List<string>[] list = new List<string>[3];

So, each list inside has 3 elements, but how do I access the last of these lists?

+3
source share
2 answers

You can use Enumerable.Last () :

string lastElement = list.Last().Last();

The first call will return the last List<string>, and the second will return the last line in this list.

Alternatively, since you know the length of the array, you can access the list directly and do:

string lastElement = list[2].Last();

If you know in advance that you will always have 3 lists with 3 elements, you might consider using a multidimensional array:

string[,] matrix = new string[3,3];

// fill it in..

string last = matrix[2,2];
+19
source

[[1,2,3],[4,5,6],[7,8,9]] 9, list.Last().Last(). [3,6,9], list.Select(sublist => sublist.Last()).

+6

Source: https://habr.com/ru/post/1758477/


All Articles