Array.LastIndexOf Yöntem

Tanım

Bir değerin tek boyutlu Array veya öğesinin bir bölümünde son oluşumunun dizinini Arraydöndürür.

Aşırı Yüklemeler

Name Description
LastIndexOf(Array, Object)

Belirtilen nesneyi arar ve tüm tek boyutlu Arrayiçindeki son oluşumun dizinini döndürür.

LastIndexOf(Array, Object, Int32)

Belirtilen nesneyi arar ve ilk öğeden belirtilen dizine genişleten tek boyutlu Array öğe aralığındaki son oluşumun dizinini döndürür.

LastIndexOf(Array, Object, Int32, Int32)

Belirtilen nesneyi arar ve belirtilen öğe sayısını içeren ve belirtilen dizinde biten tek boyutlu Array öğe aralığındaki son oluşumun dizinini döndürür.

LastIndexOf<T>(T[], T)

Belirtilen nesneyi arar ve içindeki Arrayson oluşumun dizinini döndürür.

LastIndexOf<T>(T[], T, Int32)

Belirtilen nesneyi arar ve içindeki ilk öğeden belirtilen dizine genişleten öğe Array aralığındaki son oluşumun dizinini döndürür.

LastIndexOf<T>(T[], T, Int32, Int32)

Belirtilen nesneyi arar ve içinde belirtilen öğe sayısını içeren ve belirtilen dizinde Array biten öğe aralığındaki son oluşumun dizinini döndürür.

LastIndexOf(Array, Object)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve tüm tek boyutlu Arrayiçindeki son oluşumun dizinini döndürür.

public:
 static int LastIndexOf(Array ^ array, System::Object ^ value);
public static int LastIndexOf(Array array, object value);
public static int LastIndexOf(Array array, object? value);
static member LastIndexOf : Array * obj -> int
Public Shared Function LastIndexOf (array As Array, value As Object) As Integer

Parametreler

array
Array

Aranacak tek boyutlu Array .

value
Object

içinde arraybulunacak nesne.

Döndürülenler

bulunursa, öğesinin tamamında arrayson oluşumunun value dizini; aksi takdirde dizinin alt sınırı eksi 1 olur.

Özel durumlar

array, null'e eşittir.

array çok boyutludur.

Örnekler

Aşağıdaki kod örneğinde, bir dizide belirtilen öğenin son oluşumunun dizininin nasıl belirleneceği gösterilmektedir.

let printIndexAndValues (arr: 'a []) =
   for i = arr.GetLowerBound 0 to arr.GetUpperBound 0 do
      printfn $"\t[{i}]:\t{arr[i]}"

// Creates and initializes a new Array with three elements of the same value.
let myArray = 
   [| "the"; "quick"; "brown"; "fox"
      "jumps"; "over"; "the"; "lazy"
      "dog"; "in"; "the"; "barn" |]

// Displays the values of the Array.
printfn "The Array contains the following values:"
printIndexAndValues myArray

// Searches for the last occurrence of the duplicated value.
let myString = "the"
let myIndex = Array.LastIndexOf(myArray, myString)
printfn $"The last occurrence of \"{myString}\" is at index {myIndex}."

// Searches for the last occurrence of the duplicated value in the first section of the Array.
let myIndex = Array.LastIndexOf(myArray, myString, 8)
printfn $"The last occurrence of \"{myString}\" between the start and index 8 is at index {myIndex}."

// Searches for the last occurrence of the duplicated value in a section of the Array.
// Note that the start index is greater than the end index because the search is done backward.
let myIndex = Array.LastIndexOf( myArray, myString, 10, 6 )
printfn $"The last occurrence of \"{myString}\" between index 5 and index 10 is at index {myIndex}."


//      This code produces the following output.
//
//      The Array contains the following values:
//         [0]:    the
//         [1]:    quick
//         [2]:    brown
//         [3]:    fox
//         [4]:    jumps
//         [5]:    over
//         [6]:    the
//         [7]:    lazy
//         [8]:    dog
//         [9]:    in
//         [10]:    the
//         [11]:    barn
//      The last occurrence of "the" is at index 10.
//      The last occurrence of "the" between the start and index 8 is at index 6.
//      The last occurrence of "the" between index 5 and index 10 is at index 10.
// Creates and initializes a new Array with three elements of the same value.
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 );

// Displays the values of the Array.
Console.WriteLine( "The Array contains the following values:" );
PrintIndexAndValues( myArray );

// Searches for the last occurrence of the duplicated value.
string myString = "the";
int myIndex = Array.LastIndexOf( myArray, myString );
Console.WriteLine( "The last occurrence of \"{0}\" is at index {1}.", myString, myIndex );

// Searches for the last occurrence of the duplicated value in the first section of the Array.
myIndex = Array.LastIndexOf( myArray, myString, 8 );
Console.WriteLine( "The last occurrence of \"{0}\" between the start and index 8 is at index {1}.", myString, myIndex );

// Searches for the last occurrence of the duplicated value in a section of the Array.
// Note that the start index is greater than the end index because the search is done backward.
myIndex = Array.LastIndexOf( myArray, myString, 10, 6 );
Console.WriteLine( "The last occurrence of \"{0}\" between index 5 and index 10 is at index {1}.", myString, myIndex );

void PrintIndexAndValues( Array anArray )  {
   for ( int i = anArray.GetLowerBound(0); i <= anArray.GetUpperBound(0); i++ )
      Console.WriteLine( "\t[{0}]:\t{1}", i, anArray.GetValue( i ) );
}

/*
This code produces the following output.

The Array contains the following values:
   [0]:    the
   [1]:    quick
   [2]:    brown
   [3]:    fox
   [4]:    jumps
   [5]:    over
   [6]:    the
   [7]:    lazy
   [8]:    dog
   [9]:    in
   [10]:    the
   [11]:    barn
The last occurrence of "the" is at index 10.
The last occurrence of "the" between the start and index 8 is at index 6.
The last occurrence of "the" between index 5 and index 10 is at index 10.
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new Array with three elements of
        ' the same value.
        Dim myArray As Array = Array.CreateInstance(GetType(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)
        
        ' Displays the values of the Array.
        Console.WriteLine("The Array contains the following values:")
        PrintIndexAndValues(myArray)
        
        ' Searches for the last occurrence of the duplicated value.
        Dim myString As String = "the"
        Dim myIndex As Integer = Array.LastIndexOf(myArray, myString)
        Console.WriteLine("The last occurrence of ""{0}"" is at index {1}.", _
           myString, myIndex)
        
        ' Searches for the last occurrence of the duplicated value in the first
        ' section of the Array.
        myIndex = Array.LastIndexOf(myArray, myString, 8)
        Console.WriteLine("The last occurrence of ""{0}"" between the start " _
           + "and index 8 is at index {1}.", myString, myIndex)
        
        ' Searches for the last occurrence of the duplicated value in a section
        ' of the Array.  Note that the start index is greater than the end
        ' index because the search is done backward.
        myIndex = Array.LastIndexOf(myArray, myString, 10, 6)
        Console.WriteLine("The last occurrence of ""{0}"" between index 5 " _
           + "and index 10 is at index {1}.", myString, myIndex)
    End Sub
    
    
    Public Shared Sub PrintIndexAndValues(myArray As Array)
        Dim i As Integer
        For i = myArray.GetLowerBound(0) To myArray.GetUpperBound(0)
            Console.WriteLine(ControlChars.Tab + "[{0}]:" + ControlChars.Tab _
               + "{1}", i, myArray.GetValue(i))
        Next i
    End Sub
End Class

' This code produces the following output.
' 
' The Array contains the following values:
'     [0]:    the
'     [1]:    quick
'     [2]:    brown
'     [3]:    fox
'     [4]:    jumps
'     [5]:    over
'     [6]:    the
'     [7]:    lazy
'     [8]:    dog
'     [9]:    in
'     [10]:    the
'     [11]:    barn
' The last occurrence of "the" is at index 10.
' The last occurrence of "the" between the start and index 8 is at index 6.
' The last occurrence of "the" between index 5 and index 10 is at index 10.

Açıklamalar

Tek boyutlu Array , son öğeden başlayıp ilk öğede biten geriye doğru aranılır.

öğeleri yöntemi kullanılarak belirtilen değerle Object.Equals karşılaştırılır. Öğe türü bir nonintrinsic (kullanıcı tanımlı) türüyse, Equals bu türün uygulaması kullanılır.

Çoğu dizi sıfırın alt sınırına sahip olacağından, bu yöntem genellikle bulunamazsa value -1 döndürür. Dizinin alt sınırı eşittir Int32.MinValue ve value bulunamaz nadir durumda, bu yöntem döndürürInt32.MaxValue.System.Int32.MinValue - 1

Bu yöntem bir O(n) işlemidir; burada n değeridir Lengtharray.

Bu yöntem, parametresi tarafından value belirtilen öğesinin Array mevcut olup olmadığını Object belirlemek için ve CompareTo yöntemlerini kullanırEquals.

CompareTo koleksiyondaki item nesneler üzerinde parametresinin yöntemleri.

Ayrıca bkz.

Şunlara uygulanır

LastIndexOf(Array, Object, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve ilk öğeden belirtilen dizine genişleten tek boyutlu Array öğe aralığındaki son oluşumun dizinini döndürür.

public:
 static int LastIndexOf(Array ^ array, System::Object ^ value, int startIndex);
public static int LastIndexOf(Array array, object value, int startIndex);
public static int LastIndexOf(Array array, object? value, int startIndex);
static member LastIndexOf : Array * obj * int -> int
Public Shared Function LastIndexOf (array As Array, value As Object, startIndex As Integer) As Integer

Parametreler

array
Array

Aranacak tek boyutlu Array .

value
Object

içinde arraybulunacak nesne.

startIndex
Int32

Geriye dönük aramanın başlangıç dizini.

Döndürülenler

içindeki öğe array aralığındaki son oluşumunun value dizini, ilk öğeden startIndexbulunursa öğesine genişletir; aksi takdirde dizinin alt sınırı eksi 1 olur.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

array çok boyutludur.

Örnekler

Aşağıdaki kod örneğinde, bir dizide belirtilen öğenin son oluşumunun dizininin nasıl belirleneceği gösterilmektedir.

let printIndexAndValues (arr: 'a []) =
   for i = arr.GetLowerBound 0 to arr.GetUpperBound 0 do
      printfn $"\t[{i}]:\t{arr[i]}"

// Creates and initializes a new Array with three elements of the same value.
let myArray = 
   [| "the"; "quick"; "brown"; "fox"
      "jumps"; "over"; "the"; "lazy"
      "dog"; "in"; "the"; "barn" |]

// Displays the values of the Array.
printfn "The Array contains the following values:"
printIndexAndValues myArray

// Searches for the last occurrence of the duplicated value.
let myString = "the"
let myIndex = Array.LastIndexOf(myArray, myString)
printfn $"The last occurrence of \"{myString}\" is at index {myIndex}."

// Searches for the last occurrence of the duplicated value in the first section of the Array.
let myIndex = Array.LastIndexOf(myArray, myString, 8)
printfn $"The last occurrence of \"{myString}\" between the start and index 8 is at index {myIndex}."

// Searches for the last occurrence of the duplicated value in a section of the Array.
// Note that the start index is greater than the end index because the search is done backward.
let myIndex = Array.LastIndexOf( myArray, myString, 10, 6 )
printfn $"The last occurrence of \"{myString}\" between index 5 and index 10 is at index {myIndex}."


//      This code produces the following output.
//
//      The Array contains the following values:
//         [0]:    the
//         [1]:    quick
//         [2]:    brown
//         [3]:    fox
//         [4]:    jumps
//         [5]:    over
//         [6]:    the
//         [7]:    lazy
//         [8]:    dog
//         [9]:    in
//         [10]:    the
//         [11]:    barn
//      The last occurrence of "the" is at index 10.
//      The last occurrence of "the" between the start and index 8 is at index 6.
//      The last occurrence of "the" between index 5 and index 10 is at index 10.
// Creates and initializes a new Array with three elements of the same value.
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 );

// Displays the values of the Array.
Console.WriteLine( "The Array contains the following values:" );
PrintIndexAndValues( myArray );

// Searches for the last occurrence of the duplicated value.
string myString = "the";
int myIndex = Array.LastIndexOf( myArray, myString );
Console.WriteLine( "The last occurrence of \"{0}\" is at index {1}.", myString, myIndex );

// Searches for the last occurrence of the duplicated value in the first section of the Array.
myIndex = Array.LastIndexOf( myArray, myString, 8 );
Console.WriteLine( "The last occurrence of \"{0}\" between the start and index 8 is at index {1}.", myString, myIndex );

// Searches for the last occurrence of the duplicated value in a section of the Array.
// Note that the start index is greater than the end index because the search is done backward.
myIndex = Array.LastIndexOf( myArray, myString, 10, 6 );
Console.WriteLine( "The last occurrence of \"{0}\" between index 5 and index 10 is at index {1}.", myString, myIndex );

void PrintIndexAndValues( Array anArray )  {
   for ( int i = anArray.GetLowerBound(0); i <= anArray.GetUpperBound(0); i++ )
      Console.WriteLine( "\t[{0}]:\t{1}", i, anArray.GetValue( i ) );
}

/*
This code produces the following output.

The Array contains the following values:
   [0]:    the
   [1]:    quick
   [2]:    brown
   [3]:    fox
   [4]:    jumps
   [5]:    over
   [6]:    the
   [7]:    lazy
   [8]:    dog
   [9]:    in
   [10]:    the
   [11]:    barn
The last occurrence of "the" is at index 10.
The last occurrence of "the" between the start and index 8 is at index 6.
The last occurrence of "the" between index 5 and index 10 is at index 10.
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new Array with three elements of
        ' the same value.
        Dim myArray As Array = Array.CreateInstance(GetType(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)
        
        ' Displays the values of the Array.
        Console.WriteLine("The Array contains the following values:")
        PrintIndexAndValues(myArray)
        
        ' Searches for the last occurrence of the duplicated value.
        Dim myString As String = "the"
        Dim myIndex As Integer = Array.LastIndexOf(myArray, myString)
        Console.WriteLine("The last occurrence of ""{0}"" is at index {1}.", _
           myString, myIndex)
        
        ' Searches for the last occurrence of the duplicated value in the first
        ' section of the Array.
        myIndex = Array.LastIndexOf(myArray, myString, 8)
        Console.WriteLine("The last occurrence of ""{0}"" between the start " _
           + "and index 8 is at index {1}.", myString, myIndex)
        
        ' Searches for the last occurrence of the duplicated value in a section
        ' of the Array.  Note that the start index is greater than the end
        ' index because the search is done backward.
        myIndex = Array.LastIndexOf(myArray, myString, 10, 6)
        Console.WriteLine("The last occurrence of ""{0}"" between index 5 " _
           + "and index 10 is at index {1}.", myString, myIndex)
    End Sub
    
    
    Public Shared Sub PrintIndexAndValues(myArray As Array)
        Dim i As Integer
        For i = myArray.GetLowerBound(0) To myArray.GetUpperBound(0)
            Console.WriteLine(ControlChars.Tab + "[{0}]:" + ControlChars.Tab _
               + "{1}", i, myArray.GetValue(i))
        Next i
    End Sub
End Class

' This code produces the following output.
' 
' The Array contains the following values:
'     [0]:    the
'     [1]:    quick
'     [2]:    brown
'     [3]:    fox
'     [4]:    jumps
'     [5]:    over
'     [6]:    the
'     [7]:    lazy
'     [8]:    dog
'     [9]:    in
'     [10]:    the
'     [11]:    barn
' The last occurrence of "the" is at index 10.
' The last occurrence of "the" between the start and index 8 is at index 6.
' The last occurrence of "the" between index 5 and index 10 is at index 10.

Açıklamalar

Tek boyutlu Array , ilk öğeden startIndex başlayıp sonunda geriye doğru aranılır.

öğeleri yöntemi kullanılarak belirtilen değerle Object.Equals karşılaştırılır. Öğe türü bir nonintrinsic (kullanıcı tanımlı) türüyse, Equals bu türün uygulaması kullanılır.

Çoğu dizi sıfırın alt sınırına sahip olacağından, bu yöntem genellikle bulunamazsa value -1 döndürür. Dizinin alt sınırı eşittir Int32.MinValue ve value bulunamaz nadir durumda, bu yöntem döndürürInt32.MaxValue.System.Int32.MinValue - 1

Bu yöntem bir O(n) işlemidir; burada n öğesinin başından öğesine arraystartIndexkadar olan öğe sayısıdır.

Bu yöntem, parametresi tarafından value belirtilen öğesinin Array mevcut olup olmadığını Object belirlemek için ve CompareTo yöntemlerini kullanırEquals.

Ayrıca bkz.

Şunlara uygulanır

LastIndexOf(Array, Object, Int32, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve belirtilen öğe sayısını içeren ve belirtilen dizinde biten tek boyutlu Array öğe aralığındaki son oluşumun dizinini döndürür.

public:
 static int LastIndexOf(Array ^ array, System::Object ^ value, int startIndex, int count);
public static int LastIndexOf(Array array, object value, int startIndex, int count);
public static int LastIndexOf(Array array, object? value, int startIndex, int count);
static member LastIndexOf : Array * obj * int * int -> int
Public Shared Function LastIndexOf (array As Array, value As Object, startIndex As Integer, count As Integer) As Integer

Parametreler

array
Array

Aranacak tek boyutlu Array .

value
Object

içinde arraybulunacak nesne.

startIndex
Int32

Geriye dönük aramanın başlangıç dizini.

count
Int32

Bölümde aranacak öğe sayısı.

Döndürülenler

içinde belirtilen count öğe sayısını içeren öğe aralığındaki son oluşumunun valuearray dizini ve bulunursa öğesinde startIndexbiter; aksi takdirde dizinin alt sınırı eksi 1 olur.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

-veya-

count, sıfırdan küçüktür.

-veya-

startIndex ve count içinde arraygeçerli bir bölüm belirtmeyin.

array çok boyutludur.

Örnekler

Aşağıdaki kod örneğinde, bir dizide belirtilen öğenin son oluşumunun dizininin nasıl belirleneceği gösterilmektedir. Yöntemin LastIndexOf geriye dönük bir arama olduğunu unutmayın; bu nedenle, count küçük veya buna eşit olmalıdır (startIndex dizinin alt sınırı artı 1 çıkarılır).

let printIndexAndValues (arr: 'a []) =
   for i = arr.GetLowerBound 0 to arr.GetUpperBound 0 do
      printfn $"\t[{i}]:\t{arr[i]}"

// Creates and initializes a new Array with three elements of the same value.
let myArray = 
   [| "the"; "quick"; "brown"; "fox"
      "jumps"; "over"; "the"; "lazy"
      "dog"; "in"; "the"; "barn" |]

// Displays the values of the Array.
printfn "The Array contains the following values:"
printIndexAndValues myArray

// Searches for the last occurrence of the duplicated value.
let myString = "the"
let myIndex = Array.LastIndexOf(myArray, myString)
printfn $"The last occurrence of \"{myString}\" is at index {myIndex}."

// Searches for the last occurrence of the duplicated value in the first section of the Array.
let myIndex = Array.LastIndexOf(myArray, myString, 8)
printfn $"The last occurrence of \"{myString}\" between the start and index 8 is at index {myIndex}."

// Searches for the last occurrence of the duplicated value in a section of the Array.
// Note that the start index is greater than the end index because the search is done backward.
let myIndex = Array.LastIndexOf( myArray, myString, 10, 6 )
printfn $"The last occurrence of \"{myString}\" between index 5 and index 10 is at index {myIndex}."


//      This code produces the following output.
//
//      The Array contains the following values:
//         [0]:    the
//         [1]:    quick
//         [2]:    brown
//         [3]:    fox
//         [4]:    jumps
//         [5]:    over
//         [6]:    the
//         [7]:    lazy
//         [8]:    dog
//         [9]:    in
//         [10]:    the
//         [11]:    barn
//      The last occurrence of "the" is at index 10.
//      The last occurrence of "the" between the start and index 8 is at index 6.
//      The last occurrence of "the" between index 5 and index 10 is at index 10.
// Creates and initializes a new Array with three elements of the same value.
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 );

// Displays the values of the Array.
Console.WriteLine( "The Array contains the following values:" );
PrintIndexAndValues( myArray );

// Searches for the last occurrence of the duplicated value.
string myString = "the";
int myIndex = Array.LastIndexOf( myArray, myString );
Console.WriteLine( "The last occurrence of \"{0}\" is at index {1}.", myString, myIndex );

// Searches for the last occurrence of the duplicated value in the first section of the Array.
myIndex = Array.LastIndexOf( myArray, myString, 8 );
Console.WriteLine( "The last occurrence of \"{0}\" between the start and index 8 is at index {1}.", myString, myIndex );

// Searches for the last occurrence of the duplicated value in a section of the Array.
// Note that the start index is greater than the end index because the search is done backward.
myIndex = Array.LastIndexOf( myArray, myString, 10, 6 );
Console.WriteLine( "The last occurrence of \"{0}\" between index 5 and index 10 is at index {1}.", myString, myIndex );

void PrintIndexAndValues( Array anArray )  {
   for ( int i = anArray.GetLowerBound(0); i <= anArray.GetUpperBound(0); i++ )
      Console.WriteLine( "\t[{0}]:\t{1}", i, anArray.GetValue( i ) );
}

/*
This code produces the following output.

The Array contains the following values:
   [0]:    the
   [1]:    quick
   [2]:    brown
   [3]:    fox
   [4]:    jumps
   [5]:    over
   [6]:    the
   [7]:    lazy
   [8]:    dog
   [9]:    in
   [10]:    the
   [11]:    barn
The last occurrence of "the" is at index 10.
The last occurrence of "the" between the start and index 8 is at index 6.
The last occurrence of "the" between index 5 and index 10 is at index 10.
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a new Array with three elements of
        ' the same value.
        Dim myArray As Array = Array.CreateInstance(GetType(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)
        
        ' Displays the values of the Array.
        Console.WriteLine("The Array contains the following values:")
        PrintIndexAndValues(myArray)
        
        ' Searches for the last occurrence of the duplicated value.
        Dim myString As String = "the"
        Dim myIndex As Integer = Array.LastIndexOf(myArray, myString)
        Console.WriteLine("The last occurrence of ""{0}"" is at index {1}.", _
           myString, myIndex)
        
        ' Searches for the last occurrence of the duplicated value in the first
        ' section of the Array.
        myIndex = Array.LastIndexOf(myArray, myString, 8)
        Console.WriteLine("The last occurrence of ""{0}"" between the start " _
           + "and index 8 is at index {1}.", myString, myIndex)
        
        ' Searches for the last occurrence of the duplicated value in a section
        ' of the Array.  Note that the start index is greater than the end
        ' index because the search is done backward.
        myIndex = Array.LastIndexOf(myArray, myString, 10, 6)
        Console.WriteLine("The last occurrence of ""{0}"" between index 5 " _
           + "and index 10 is at index {1}.", myString, myIndex)
    End Sub
    
    
    Public Shared Sub PrintIndexAndValues(myArray As Array)
        Dim i As Integer
        For i = myArray.GetLowerBound(0) To myArray.GetUpperBound(0)
            Console.WriteLine(ControlChars.Tab + "[{0}]:" + ControlChars.Tab _
               + "{1}", i, myArray.GetValue(i))
        Next i
    End Sub
End Class

' This code produces the following output.
' 
' The Array contains the following values:
'     [0]:    the
'     [1]:    quick
'     [2]:    brown
'     [3]:    fox
'     [4]:    jumps
'     [5]:    over
'     [6]:    the
'     [7]:    lazy
'     [8]:    dog
'     [9]:    in
'     [10]:    the
'     [11]:    barn
' The last occurrence of "the" is at index 10.
' The last occurrence of "the" between the start and index 8 is at index 6.
' The last occurrence of "the" between index 5 and index 10 is at index 10.

Açıklamalar

0'dan büyüksecount, eksi artı 1 ile başlayan startIndex ve biten startIndexcount tek boyutlu Array geriye doğru arama yapılır.

öğeleri yöntemi kullanılarak belirtilen değerle Object.Equals karşılaştırılır. Öğe türü bir nonintrinsic (kullanıcı tanımlı) türüyse,Equals bu türün uygulaması kullanılır.

Çoğu dizi sıfırın alt sınırına sahip olacağından, bu yöntem genellikle bulunamazsa value -1 döndürür. Dizinin alt sınırı eşittir Int32.MinValue ve value bulunamaz nadir durumda, bu yöntem döndürürInt32.MaxValue.System.Int32.MinValue - 1

Bu yöntem bir O(n) işlemidir; burada n olur count.

Bu yöntem, parametresi tarafından value belirtilen öğesinin Array mevcut olup olmadığını Object belirlemek için ve CompareTo yöntemlerini kullanırEquals.

Ayrıca bkz.

Şunlara uygulanır

LastIndexOf<T>(T[], T)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve içindeki Arrayson oluşumun dizinini döndürür.

public:
generic <typename T>
 static int LastIndexOf(cli::array <T> ^ array, T value);
public static int LastIndexOf<T>(T[] array, T value);
static member LastIndexOf : 'T[] * 'T -> int
Public Shared Function LastIndexOf(Of T) (array As T(), value As T) As Integer

Tür Parametreleri

T

Dizinin öğelerinin türü.

Parametreler

array
T[]

Aranacak tek boyutlu, sıfır tabanlı Array .

value
T

içinde arraybulunacak nesne.

Döndürülenler

tüm içinde öğesinin son oluşumunun valuearraysıfır tabanlı dizini; bulunursa, aksi takdirde -1.

Özel durumlar

array, null'e eşittir.

Örnekler

Aşağıdaki kod örneği, yönteminin üç genel aşırı yüklemesini LastIndexOf de gösterir. Dizin konumu 0 ve dizin konumu 5'te iki kez görüntülenen bir girişle bir dize dizisi oluşturulur. LastIndexOf<T>(T[], T) yöntemi aşırı yüklemesi, sonundan tüm diziyi arar ve dizenin ikinci oluşumunu bulur. LastIndexOf<T>(T[], T, Int32) Yöntem aşırı yüklemesi, dizin konumu 3'le başlayıp dizinin başına devam ederek diziyi geriye doğru aramak için kullanılır ve dizenin ilk oluşumunu bulur. Son olarak, LastIndexOf<T>(T[], T, Int32, Int32) yöntem aşırı yüklemesi dizin konumu 4'te başlayıp geriye doğru genişleterek dört girdiden oluşan bir aralığı aramak için kullanılır (yani, 4, 3, 2 ve 1 konumlarındaki öğeleri arar); bu arama -1 döndürür çünkü bu aralıkta arama dizesinin hiçbir örneği yoktur.

string[] dinosaurs = { "Tyrannosaurus",
    "Amargasaurus",
    "Mamenchisaurus",
    "Brachiosaurus",
    "Deinonychus",
    "Tyrannosaurus",
    "Compsognathus" };

Console.WriteLine();
foreach(string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\"): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus"));

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 3): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3));

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 4, 4): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4));

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Brachiosaurus
Deinonychus
Tyrannosaurus
Compsognathus

Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1
*/
open System

let dinosaurs = 
    [| "Tyrannosaurus"
       "Amargasaurus"
       "Mamenchisaurus"
       "Brachiosaurus"
       "Deinonychus"
       "Tyrannosaurus"
       "Compsognathus" |]

printfn ""
for dino in dinosaurs do
    printfn $"{dino}"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus")
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\"): %i"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3)
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 3): %i"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4)
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 4, 4): %i"

// This code example produces the following output:
//    
//    Tyrannosaurus
//    Amargasaurus
//    Mamenchisaurus
//    Brachiosaurus
//    Deinonychus
//    Tyrannosaurus
//    Compsognathus
//    
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5
//
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0
//
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1
Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs() As String = { "Tyrannosaurus", _
            "Amargasaurus", _
            "Mamenchisaurus", _
            "Brachiosaurus", _
            "Deinonychus", _
            "Tyrannosaurus", _
            "Compsognathus" }

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus""): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus"))

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus"", 3): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3))

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus"", 4, 4): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4))

    End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Brachiosaurus
'Deinonychus
'Tyrannosaurus
'Compsognathus
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1

Açıklamalar

Array, son öğeden başlayıp ilk öğede sona ererek geriye doğru arandı.

öğeleri yöntemi kullanılarak belirtilen değerle Object.Equals karşılaştırılır. Öğe türü bir nonintrinsic (kullanıcı tanımlı) türüyse, Equals bu türün uygulaması kullanılır.

Bu yöntem bir O(n) işlemidir; burada n değeridir Lengtharray.

Ayrıca bkz.

Şunlara uygulanır

LastIndexOf<T>(T[], T, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve içindeki ilk öğeden belirtilen dizine genişleten öğe Array aralığındaki son oluşumun dizinini döndürür.

public:
generic <typename T>
 static int LastIndexOf(cli::array <T> ^ array, T value, int startIndex);
public static int LastIndexOf<T>(T[] array, T value, int startIndex);
static member LastIndexOf : 'T[] * 'T * int -> int
Public Shared Function LastIndexOf(Of T) (array As T(), value As T, startIndex As Integer) As Integer

Tür Parametreleri

T

Dizinin öğelerinin türü.

Parametreler

array
T[]

Aranacak tek boyutlu, sıfır tabanlı Array .

value
T

içinde arraybulunacak nesne.

startIndex
Int32

Geriye dönük aramanın sıfır tabanlı başlangıç dizini.

Döndürülenler

içindeki ilk öğeden 'e startIndexkadar uzanan öğe array aralığındaki son oluşumunun value sıfır tabanlı dizini; aksi takdirde -1.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

Örnekler

Aşağıdaki kod örneği, yönteminin üç genel aşırı yüklemesini LastIndexOf de gösterir. Dizin konumu 0 ve dizin konumu 5'te iki kez görüntülenen bir girişle bir dize dizisi oluşturulur. LastIndexOf<T>(T[], T) yöntemi aşırı yüklemesi, sonundan tüm diziyi arar ve dizenin ikinci oluşumunu bulur. LastIndexOf<T>(T[], T, Int32) Yöntem aşırı yüklemesi, dizin konumu 3'le başlayıp dizinin başına devam ederek diziyi geriye doğru aramak için kullanılır ve dizenin ilk oluşumunu bulur. Son olarak, LastIndexOf<T>(T[], T, Int32, Int32) yöntem aşırı yüklemesi dizin konumu 4'te başlayıp geriye doğru genişleterek dört girdiden oluşan bir aralığı aramak için kullanılır (yani, 4, 3, 2 ve 1 konumlarındaki öğeleri arar); bu arama -1 döndürür çünkü bu aralıkta arama dizesinin hiçbir örneği yoktur.

string[] dinosaurs = { "Tyrannosaurus",
    "Amargasaurus",
    "Mamenchisaurus",
    "Brachiosaurus",
    "Deinonychus",
    "Tyrannosaurus",
    "Compsognathus" };

Console.WriteLine();
foreach(string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\"): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus"));

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 3): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3));

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 4, 4): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4));

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Brachiosaurus
Deinonychus
Tyrannosaurus
Compsognathus

Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1
*/
open System

let dinosaurs = 
    [| "Tyrannosaurus"
       "Amargasaurus"
       "Mamenchisaurus"
       "Brachiosaurus"
       "Deinonychus"
       "Tyrannosaurus"
       "Compsognathus" |]

printfn ""
for dino in dinosaurs do
    printfn $"{dino}"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus")
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\"): %i"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3)
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 3): %i"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4)
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 4, 4): %i"

// This code example produces the following output:
//    
//    Tyrannosaurus
//    Amargasaurus
//    Mamenchisaurus
//    Brachiosaurus
//    Deinonychus
//    Tyrannosaurus
//    Compsognathus
//    
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5
//
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0
//
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1
Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs() As String = { "Tyrannosaurus", _
            "Amargasaurus", _
            "Mamenchisaurus", _
            "Brachiosaurus", _
            "Deinonychus", _
            "Tyrannosaurus", _
            "Compsognathus" }

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus""): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus"))

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus"", 3): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3))

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus"", 4, 4): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4))

    End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Brachiosaurus
'Deinonychus
'Tyrannosaurus
'Compsognathus
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1

Açıklamalar

Array öğesinden startIndex başlayıp ilk öğede sona ererek geriye doğru arandı.

öğeleri yöntemi kullanılarak belirtilen değerle Object.Equals karşılaştırılır. Öğe türü bir nonintrinsic (kullanıcı tanımlı) türüyse, Equals bu türün uygulaması kullanılır.

Bu yöntem bir O(n) işlemidir; burada n öğesinin başından öğesine arraystartIndexkadar olan öğe sayısıdır.

Ayrıca bkz.

Şunlara uygulanır

LastIndexOf<T>(T[], T, Int32, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve içinde belirtilen öğe sayısını içeren ve belirtilen dizinde Array biten öğe aralığındaki son oluşumun dizinini döndürür.

public:
generic <typename T>
 static int LastIndexOf(cli::array <T> ^ array, T value, int startIndex, int count);
public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count);
static member LastIndexOf : 'T[] * 'T * int * int -> int
Public Shared Function LastIndexOf(Of T) (array As T(), value As T, startIndex As Integer, count As Integer) As Integer

Tür Parametreleri

T

Dizinin öğelerinin türü.

Parametreler

array
T[]

Aranacak tek boyutlu, sıfır tabanlı Array .

value
T

içinde arraybulunacak nesne.

startIndex
Int32

Geriye dönük aramanın sıfır tabanlı başlangıç dizini.

count
Int32

Bölümde aranacak öğe sayısı.

Döndürülenler

içinde belirtilen count öğe sayısını içeren öğe aralığındaki son oluşumunun valuearray sıfır tabanlı dizini ve bulunursa öğesinde startIndexbiter; aksi takdirde -1.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

-veya-

count, sıfırdan küçüktür.

-veya-

startIndex ve count içinde arraygeçerli bir bölüm belirtmeyin.

Örnekler

Aşağıdaki kod örneği, yönteminin üç genel aşırı yüklemesini LastIndexOf de gösterir. Dizin konumu 0 ve dizin konumu 5'te iki kez görüntülenen bir girişle bir dize dizisi oluşturulur. LastIndexOf<T>(T[], T) yöntemi aşırı yüklemesi, sonundan tüm diziyi arar ve dizenin ikinci oluşumunu bulur. LastIndexOf<T>(T[], T, Int32) Yöntem aşırı yüklemesi, dizin konumu 3'le başlayıp dizinin başına devam ederek diziyi geriye doğru aramak için kullanılır ve dizenin ilk oluşumunu bulur. Son olarak, LastIndexOf<T>(T[], T, Int32, Int32) yöntem aşırı yüklemesi dizin konumu 4'te başlayıp geriye doğru genişleterek dört girdiden oluşan bir aralığı aramak için kullanılır (yani, 4, 3, 2 ve 1 konumlarındaki öğeleri arar); bu arama -1 döndürür çünkü bu aralıkta arama dizesinin hiçbir örneği yoktur.

string[] dinosaurs = { "Tyrannosaurus",
    "Amargasaurus",
    "Mamenchisaurus",
    "Brachiosaurus",
    "Deinonychus",
    "Tyrannosaurus",
    "Compsognathus" };

Console.WriteLine();
foreach(string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\"): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus"));

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 3): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3));

Console.WriteLine(
    "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 4, 4): {0}",
    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4));

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Brachiosaurus
Deinonychus
Tyrannosaurus
Compsognathus

Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1
*/
open System

let dinosaurs = 
    [| "Tyrannosaurus"
       "Amargasaurus"
       "Mamenchisaurus"
       "Brachiosaurus"
       "Deinonychus"
       "Tyrannosaurus"
       "Compsognathus" |]

printfn ""
for dino in dinosaurs do
    printfn $"{dino}"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus")
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\"): %i"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3)
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 3): %i"

Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4)
|> printfn "\nArray.LastIndexOf(dinosaurs, \"Tyrannosaurus\", 4, 4): %i"

// This code example produces the following output:
//    
//    Tyrannosaurus
//    Amargasaurus
//    Mamenchisaurus
//    Brachiosaurus
//    Deinonychus
//    Tyrannosaurus
//    Compsognathus
//    
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5
//
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0
//
//    Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1
Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs() As String = { "Tyrannosaurus", _
            "Amargasaurus", _
            "Mamenchisaurus", _
            "Brachiosaurus", _
            "Deinonychus", _
            "Tyrannosaurus", _
            "Compsognathus" }

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus""): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus"))

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus"", 3): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3))

        Console.WriteLine(vbLf & _
            "Array.LastIndexOf(dinosaurs, ""Tyrannosaurus"", 4, 4): {0}", _
            Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4))

    End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Brachiosaurus
'Deinonychus
'Tyrannosaurus
'Compsognathus
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus"): 5
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 3): 0
'
'Array.LastIndexOf(dinosaurs, "Tyrannosaurus", 4, 4): -1

Açıklamalar

Array, 0'dan startIndex büyükse count eksi count artı 1 ile startIndex başlayıp biten geriye doğru aranılır.

öğeleri yöntemi kullanılarak belirtilen değerle Object.Equals karşılaştırılır. Öğe türü bir nonintrinsic (kullanıcı tanımlı) türüyse, Equals bu türün uygulaması kullanılır.

Bu yöntem bir O(n) işlemidir; burada n olur count.

Ayrıca bkz.

Şunlara uygulanır