I have a list which contains more than 75 thousand object. To search item from list currently I am using following code.
from nd in this.m_ListNodes
where
nd.Label == SearchValue.ToString()
select
nd;
Is this code is efficient?
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.
How often do you need to search the same list? If you’re only searching once, you might as well do a straight linear search – although you can make your current code slightly more efficient by calling
SearchValue.ToString()once before the query.If you’re going to perform this search on the same list multiple times, you should either build a
Lookupor aDictionary:or
Use a dictionary if there’s exactly one entry per label; use a lookup if there may be multiple matches.
To use these, for a lookup:
or for a dictionary: