If I have an array of ints, and I want to quickly check if a certain int value is in that array, is there a method to do that?
Share
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.
If the array is sorted, then this is quickest:
If the array is searched a lot and rarely modified, then you may find it worthwhile to sort the array after modification (using
Array.Sort) and use the above. Otherwise, use the option you prefer:IndexOfhas the best performance for unsorted arrays. The second option uses a predicate delegate, and the third requires the creation of an enumerator object.