Krivahn Doss
Krivahn Doss

Reputation: 155

Find object in a generic list by Index

This is my generic list. I would like to return the object CompanyEmail by finding the object based on the index. How do I do this ?

 List<CompanyEmail> companyEmail = (List<CompanyEmail>)ViewState["companyEmail"];

Upvotes: 0

Views: 8350

Answers (3)

Mokhtar Ashour
Mokhtar Ashour

Reputation: 600

why on index, you may use the Dictionary Class (it's generic too). http://msdn.microsoft.com/en-us/library/xfhwa508.aspx

hope I got you right.

Upvotes: 1

Habib Zare
Habib Zare

Reputation: 1204

try:

 List<Data> data = new List<Data>();
 Data temp = data[1];

in your list:

companyEmail[index];

Upvotes: 3

spinon
spinon

Reputation: 10847

This should do the trick:

http://msdn.microsoft.com/en-us/library/x1xzf2ca.aspx

Use:

List<T>.FindIndex(Predicate)

Upvotes: 0

Related Questions