Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Trick when using Array.Contains()

By , 13 Jun 2011
Rate this:
Please Sign up or sign in to vote.

The Array class already contains this capability with no casting required. The IndexOf method is a static one that returns the index of the value and a -1 if it doesn't exist.

Here is an example:

exists = Array.IndexOf(arr, "item") >= 0


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author


United States United States
No Biography provided

Comments and Discussions

GeneralSimpler and nice one. If we do not want exact matching and i... PinmemberMohammad A Rahman27-Jun-11 18:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 13 Jun 2011
Article Copyright 2011 by Ctznkane
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid