Yaron Buki
Yaron Buki

Reputation: 81

How would one find the item of a List<string> based on it's index

I would like to display text that is stored in my list. I have the index number, and would like to use the index number to get the item from the collection.

Thx

Upvotes: 0

Views: 1712

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1499740

If it's a List<string>, why not just use:

string item = list[index];

?

Upvotes: 5

alexn
alexn

Reputation: 58952

You can use ElementAt:

var item = list.ElementAt(3);

Or simply use the indexer, like:

var item = list[3];

Upvotes: 4

Related Questions