This is probably a really easy question, I want to access the last element of:
List<string>[] list = new List<string>[3];
So each list inside has 3 elements but how should I access the last of those lists?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use Enumerable.Last():
The first call will return the last
List<string>, and the second will return the last string within that list.Alternatively, since you know the length of the array, you can access the list directly, and do:
If you know, in advance, that you’re always going to have 3 lists with 3 elements, you might want to consider using a multidimensional array instead: