Searchs for object and returns the index of the last occurrence within the sub range of Array in CSharp

Description

The following code shows how to searchs for object and returns the index of the last occurrence within the sub range of Array.

Example


/*from   w w  w  .  j  av  a2s .  c o  m*/
using System;
public class SamplesArray  {

   public static void Main()  {
      Array myArray=Array.CreateInstance( typeof(String), 12 );
      myArray.SetValue( "S", 0 );
      myArray.SetValue( "X", 1 );
      myArray.SetValue( "E", 2 );
      myArray.SetValue( "T", 3 );
      myArray.SetValue( "H", 4 );
      myArray.SetValue( "W", 5 );
      myArray.SetValue( "Q", 6 );
      myArray.SetValue( "B", 7 );
      myArray.SetValue( "Z", 8 );
      myArray.SetValue( "U", 9 );
      myArray.SetValue( "P", 10 );
      myArray.SetValue( "I", 11 );

      int myIndex = Array.LastIndexOf( myArray, "Q", 10, 6 );
      Console.WriteLine(myIndex );
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var