Finds given string in the array or list. - CSharp System

CSharp examples for System:Array Search

Description

Finds given string in the array or list.

Demo Code

/********************************************************************
 *  FulcrumWeb RAD Framework - Fulcrum of your business             *
 *  Copyright (c) 2002-2010 FulcrumWeb, ALL RIGHTS RESERVED         *
 *                                                                  *
 *  THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      *
 *  FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        *
 *  COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       *
 *  AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  *
 *  AND PERMISSION FROM FULCRUMWEB. CONSULT THE END USER LICENSE    *
 *  AGREEMENT FOR INFORMATION ON ADDITIONAL RESTRICTIONS.           *
 ********************************************************************/
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Collections;
using System;/*from   ww  w .  j  a  va 2  s . c o  m*/

public class Main{
        //-------------------------------------------------------------------------
    /// <summary>
    /// Finds given string in the array or list.
    /// </summary>
    /// <param name="list">string array to find strings</param>
    /// <param name="s">string to find</param>
    /// <returns>index of the string in array of -1 if not found</returns>
    static public int IndexOf(IList list, string s)
    {
      for (int i = 0; i < list.Count; i++)
      {
        if ((string) list[i] == s) return i;
      }
      return -1;
    }
}

Related Tutorials