Dofactory.com
Dofactory.com

How to get a list item by index in C#.

Using an indexer.

We can use the indexer of the list to access the list item by its index.


var int = new List<int>() { 1, 2, 3, 4, 8, 10 };

// access list item by index

var firstInt = int[0]; 

Using the Linq ElementAt() method.


using System.Linq;

var ints = new List<int>() { 1, 2, 3, 4, 8, 10 };

var firstInt = ints.ElementAt(0);


Jack Poorte
Jack Poorte
Last updated on Sep 30, 2023



Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.