find item at index using list <T>

how would i find the item in a list<int> if i know the index of the item i am looking for. I tried list<int>.items[4] but that won't compile even though the item property exists in documentation.


Answer this question

find item at index using list <T>

  • DaveStacy

    Try this

    List<int> l=new List<int>();
    l.Add(1);
    l.Add(2);
    l.Add(3);
    l.Add(4);
    l.Add(5);

    MessageBox.Show(l[2].ToString());


  • Rafael31

    >> I tried list<int>.items[4] but that won't compile even though the item property exists in documentation.

    Well, it would be list<int>.Item(4) but that still doesn't work, as it's the indexer for the class. Use [ ] on the list object itself.



  • find item at index using list <T>