Search object and returns the index with in the range of elements in the one-dimensional Array in CSharp
Description
The following code shows how to search object and returns the index with in the range of elements in the one-dimensional Array.
Example
using System;/* w ww .jav a 2s. c om*/
public class SamplesArray {
public static void Main() {
Array myArray=Array.CreateInstance( typeof(String), 12 );
myArray.SetValue( "the", 0 );
myArray.SetValue( "quick", 1 );
myArray.SetValue( "brown", 2 );
myArray.SetValue( "fox", 3 );
myArray.SetValue( "jumps", 4 );
myArray.SetValue( "over", 5 );
myArray.SetValue( "the", 6 );
myArray.SetValue( "lazy", 7 );
myArray.SetValue( "dog", 8 );
myArray.SetValue( "in", 9 );
myArray.SetValue( "the", 10 );
myArray.SetValue( "barn", 11 );
int myIndex = Array.IndexOf( myArray, "in", 6, 5 );
Console.WriteLine(myIndex );
}
}
The code above generates the following result.