Array.LastIndexOf Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Überlädt
| Name | Beschreibung |
|---|---|
| LastIndexOf(Array, Object) |
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des gesamten eindimensionalen ArrayObjekts zurück. |
| LastIndexOf(Array, Object, Int32) |
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Bereichs von Elementen im eindimensionalen Array Element zurück, das sich vom ersten Element bis zum angegebenen Index erstreckt. |
| LastIndexOf(Array, Object, Int32, Int32) |
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Bereichs der Elemente in der eindimensionalen Array , die die angegebene Anzahl von Elementen enthält und am angegebenen Index endet. |
| LastIndexOf<T>(T[], T) |
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des gesamten ArrayObjekts zurück. |
| LastIndexOf<T>(T[], T, Int32) |
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Elementbereichs zurück, der Array sich von dem ersten Element bis zum angegebenen Index erstreckt. |
| LastIndexOf<T>(T[], T, Int32, Int32) |
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Elementbereichs zurück, der Array die angegebene Anzahl von Elementen enthält und am angegebenen Index endet. |
LastIndexOf(Array, Object)
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des gesamten eindimensionalen ArrayObjekts zurück.
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
Parameter
- value
- Object
Das Objekt, in arraydem gesucht werden soll.
Gibt zurück
Der Index des letzten Vorkommens value innerhalb des gesamten array, falls gefunden; andernfalls die untere Grenze des Arrays minus 1.
Ausnahmen
array ist null.
array ist multidimensional.
Beispiele
Das folgende Codebeispiel zeigt, wie der Index des letzten Vorkommens eines angegebenen Elements in einem Array bestimmt wird.
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.
Hinweise
Das eindimensionale Array Element wird rückwärts durchsucht, beginnend am letzten Element und endet am ersten Element.
Die Elemente werden mit der Object.Equals Methode mit dem angegebenen Wert verglichen. Wenn der Elementtyp ein nicht benutzerdefinierter (benutzerdefinierter) Typ ist, wird die Equals Implementierung dieses Typs verwendet.
Da die meisten Arrays eine untere Grenze von Null aufweisen, würde diese Methode in der Regel -1 zurückgeben, wenn value sie nicht gefunden wird. In dem seltenen Fall, dass die untere Grenze des Arrays gleich Int32.MinValue ist und value nicht gefunden wird, gibt Int32.MaxValuediese Methode zurück, was lautet System.Int32.MinValue - 1.
Bei dieser Methode handelt es sich um einen O()-Vorgang, bei dem n es sich um einen n OLength(array)-Vorgang handelt.
Diese Methode verwendet die Equals Methoden und CompareTo Methoden der Array , um zu bestimmen, ob der Object durch den value Parameter angegebene Parameter vorhanden ist.
CompareTo Methoden des item Parameters für die Objekte in der Auflistung.
Weitere Informationen
Gilt für:
LastIndexOf(Array, Object, Int32)
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Bereichs von Elementen im eindimensionalen Array Element zurück, das sich vom ersten Element bis zum angegebenen Index erstreckt.
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
Parameter
- value
- Object
Das Objekt, in arraydem gesucht werden soll.
- startIndex
- Int32
Der Startindex der Rückwärtssuche.
Gibt zurück
Der Index des letzten Vorkommens value innerhalb des Bereichs der Elemente, die array sich von dem ersten Element bis zum startIndexGefundenen erstreckt, andernfalls die untere Grenze des Arrays minus 1.
Ausnahmen
array ist null.
startIndex liegt außerhalb des Bereichs gültiger Indizes für array.
array ist multidimensional.
Beispiele
Das folgende Codebeispiel zeigt, wie der Index des letzten Vorkommens eines angegebenen Elements in einem Array bestimmt wird.
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.
Hinweise
Das eindimensionale Array Element wird rückwärts gesucht startIndex und endet am ersten Element.
Die Elemente werden mit der Object.Equals Methode mit dem angegebenen Wert verglichen. Wenn der Elementtyp ein nicht benutzerdefinierter (benutzerdefinierter) Typ ist, wird die Equals Implementierung dieses Typs verwendet.
Da die meisten Arrays eine untere Grenze von Null aufweisen, würde diese Methode in der Regel -1 zurückgeben, wenn value sie nicht gefunden wird. In dem seltenen Fall, dass die untere Grenze des Arrays gleich Int32.MinValue ist und value nicht gefunden wird, gibt Int32.MaxValuediese Methode zurück, was lautet System.Int32.MinValue - 1.
Diese Methode ist ein O(n)-Vorgang, wobei n die Anzahl der Elemente vom Anfang bis array zum startIndex.
Diese Methode verwendet die Equals Methoden und CompareTo Methoden der Array , um zu bestimmen, ob der Object durch den value Parameter angegebene Parameter vorhanden ist.
Weitere Informationen
Gilt für:
LastIndexOf(Array, Object, Int32, Int32)
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Bereichs der Elemente in der eindimensionalen Array , die die angegebene Anzahl von Elementen enthält und am angegebenen Index endet.
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
Parameter
- value
- Object
Das Objekt, in arraydem gesucht werden soll.
- startIndex
- Int32
Der Startindex der Rückwärtssuche.
- count
- Int32
Die Anzahl der zu durchsuchenden Elemente im Abschnitt.
Gibt zurück
Der Index des letzten Vorkommens value innerhalb des Elementbereichs, in array dem die Anzahl der in count und endenden Elemente enthalten startIndexist, falls gefunden; andernfalls die untere Grenze des Arrays minus 1.
Ausnahmen
array ist null.
startIndex liegt außerhalb des Bereichs gültiger Indizes für array.
-oder-
count ist kleiner als 0 (null).
-oder-
startIndex und count geben Sie keinen gültigen Abschnitt in array.
array ist multidimensional.
Beispiele
Das folgende Codebeispiel zeigt, wie der Index des letzten Vorkommens eines angegebenen Elements in einem Array bestimmt wird. Beachten Sie, dass die LastIndexOf Methode eine Rückwärtssuche ist. Daher count muss sie kleiner oder gleich (startIndex minus der unteren Grenze des Arrays plus 1) sein.
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.
Hinweise
Die eindimensionale Array Suche beginnt mit startIndex minus 1 und endet mit startIndex minus count 1, wenn count größer als 0 ist.
Die Elemente werden mit der Object.Equals Methode mit dem angegebenen Wert verglichen. Wenn der Elementtyp ein nicht benutzerdefinierter (benutzerdefinierter) Typ ist, wird dieEquals Implementierung dieses Typs verwendet.
Da die meisten Arrays eine untere Grenze von Null aufweisen, würde diese Methode in der Regel -1 zurückgeben, wenn value sie nicht gefunden wird. In dem seltenen Fall, dass die untere Grenze des Arrays gleich Int32.MinValue ist und value nicht gefunden wird, gibt Int32.MaxValuediese Methode zurück, was lautet System.Int32.MinValue - 1.
Bei dieser Methode handelt es sich um einen O()-Vorgang, wobei n es sich um einen O(n)-Vorgang handeltcount.
Diese Methode verwendet die Equals Methoden und CompareTo Methoden der Array , um zu bestimmen, ob der Object durch den value Parameter angegebene Parameter vorhanden ist.
Weitere Informationen
Gilt für:
LastIndexOf<T>(T[], T)
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des gesamten ArrayObjekts zurück.
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
Typparameter
- T
Der Typ der Elemente des Arrays.
Parameter
- array
- T[]
Die eindimensionale, nullbasierte Array Suche.
- value
- T
Das Objekt, in arraydem gesucht werden soll.
Gibt zurück
Der nullbasierte Index des letzten Vorkommens innerhalb des value gesamten array, falls gefunden; andernfalls -1.
Ausnahmen
array ist null.
Beispiele
Im folgenden Codebeispiel werden alle drei generischen Überladungen der LastIndexOf Methode veranschaulicht. Es wird ein Array mit Zeichenfolgen erstellt, wobei ein Eintrag zweimal angezeigt wird, an Indexspeicherort 0 und Indexspeicherort 5. Die LastIndexOf<T>(T[], T) Methodenüberladung durchsucht das gesamte Array vom Ende und findet das zweite Vorkommen der Zeichenfolge. Die LastIndexOf<T>(T[], T, Int32) Methodenüberladung wird verwendet, um das Array mit Indexposition 3 rückwärts zu durchsuchen und den Anfang des Arrays fortzusetzen und das erste Vorkommen der Zeichenfolge zu finden. Schließlich wird die LastIndexOf<T>(T[], T, Int32, Int32) Methodenüberladung verwendet, um einen Bereich von vier Einträgen zu durchsuchen, beginnend am Indexspeicherort 4 und rückwärts (d. h., sie durchsucht die Elemente an den Speicherorten 4, 3, 2 und 1); diese Suche gibt -1 zurück, da keine Instanzen der Suchzeichenfolge in diesem Bereich vorhanden sind.
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
Hinweise
Die Array Suche erfolgt rückwärts beginnend am letzten Element und endet mit dem ersten Element.
Die Elemente werden mit der Object.Equals Methode mit dem angegebenen Wert verglichen. Wenn der Elementtyp ein nicht benutzerdefinierter (benutzerdefinierter) Typ ist, wird die Equals Implementierung dieses Typs verwendet.
Bei dieser Methode handelt es sich um einen O()-Vorgang, bei dem n es sich um einen n OLength(array)-Vorgang handelt.
Weitere Informationen
Gilt für:
LastIndexOf<T>(T[], T, Int32)
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Elementbereichs zurück, der Array sich von dem ersten Element bis zum angegebenen Index erstreckt.
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
Typparameter
- T
Der Typ der Elemente des Arrays.
Parameter
- array
- T[]
Die eindimensionale, nullbasierte Array Suche.
- value
- T
Das Objekt, in arraydem gesucht werden soll.
- startIndex
- Int32
Der nullbasierte Startindex der Rückwärtssuche.
Gibt zurück
Der nullbasierte Index des letzten Vorkommens value innerhalb des Elementbereichs array , der sich von dem ersten Element bis zum startIndexgefundenen Element erstreckt, andernfalls -1.
Ausnahmen
array ist null.
startIndex liegt außerhalb des Bereichs gültiger Indizes für array.
Beispiele
Im folgenden Codebeispiel werden alle drei generischen Überladungen der LastIndexOf Methode veranschaulicht. Es wird ein Array mit Zeichenfolgen erstellt, wobei ein Eintrag zweimal angezeigt wird, an Indexspeicherort 0 und Indexspeicherort 5. Die LastIndexOf<T>(T[], T) Methodenüberladung durchsucht das gesamte Array vom Ende und findet das zweite Vorkommen der Zeichenfolge. Die LastIndexOf<T>(T[], T, Int32) Methodenüberladung wird verwendet, um das Array mit Indexposition 3 rückwärts zu durchsuchen und den Anfang des Arrays fortzusetzen und das erste Vorkommen der Zeichenfolge zu finden. Schließlich wird die LastIndexOf<T>(T[], T, Int32, Int32) Methodenüberladung verwendet, um einen Bereich von vier Einträgen zu durchsuchen, beginnend am Indexspeicherort 4 und rückwärts (d. h., sie durchsucht die Elemente an den Speicherorten 4, 3, 2 und 1); diese Suche gibt -1 zurück, da keine Instanzen der Suchzeichenfolge in diesem Bereich vorhanden sind.
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
Hinweise
Die Array Suche erfolgt rückwärts beginnend mit startIndex dem ersten Element und endet mit dem ersten Element.
Die Elemente werden mit der Object.Equals Methode mit dem angegebenen Wert verglichen. Wenn der Elementtyp ein nicht benutzerdefinierter (benutzerdefinierter) Typ ist, wird die Equals Implementierung dieses Typs verwendet.
Diese Methode ist ein O(n)-Vorgang, wobei n die Anzahl der Elemente vom Anfang bis array zum startIndex.
Weitere Informationen
Gilt für:
LastIndexOf<T>(T[], T, Int32, Int32)
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
- Quelle:
- Array.cs
Sucht nach dem angegebenen Objekt und gibt den Index des letzten Vorkommens innerhalb des Elementbereichs zurück, der Array die angegebene Anzahl von Elementen enthält und am angegebenen Index endet.
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
Typparameter
- T
Der Typ der Elemente des Arrays.
Parameter
- array
- T[]
Die eindimensionale, nullbasierte Array Suche.
- value
- T
Das Objekt, in arraydem gesucht werden soll.
- startIndex
- Int32
Der nullbasierte Startindex der Rückwärtssuche.
- count
- Int32
Die Anzahl der zu durchsuchenden Elemente im Abschnitt.
Gibt zurück
Der nullbasierte Index des letzten Vorkommens value innerhalb des Elementbereichs, in array dem die Anzahl der in count und endet bei gefundenen Elementen, startIndexandernfalls -1.
Ausnahmen
array ist null.
startIndex liegt außerhalb des Bereichs gültiger Indizes für array.
-oder-
count ist kleiner als 0 (null).
-oder-
startIndex und count geben Sie keinen gültigen Abschnitt in array.
Beispiele
Im folgenden Codebeispiel werden alle drei generischen Überladungen der LastIndexOf Methode veranschaulicht. Es wird ein Array mit Zeichenfolgen erstellt, wobei ein Eintrag zweimal angezeigt wird, an Indexspeicherort 0 und Indexspeicherort 5. Die LastIndexOf<T>(T[], T) Methodenüberladung durchsucht das gesamte Array vom Ende und findet das zweite Vorkommen der Zeichenfolge. Die LastIndexOf<T>(T[], T, Int32) Methodenüberladung wird verwendet, um das Array mit Indexposition 3 rückwärts zu durchsuchen und den Anfang des Arrays fortzusetzen und das erste Vorkommen der Zeichenfolge zu finden. Schließlich wird die LastIndexOf<T>(T[], T, Int32, Int32) Methodenüberladung verwendet, um einen Bereich von vier Einträgen zu durchsuchen, beginnend am Indexspeicherort 4 und rückwärts (d. h., sie durchsucht die Elemente an den Speicherorten 4, 3, 2 und 1); diese Suche gibt -1 zurück, da keine Instanzen der Suchzeichenfolge in diesem Bereich vorhanden sind.
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
Hinweise
Die Array Suche beginnt mit startIndex minus 1 und endet startIndex mit minus count 1, wenn count größer als 0 ist.
Die Elemente werden mit der Object.Equals Methode mit dem angegebenen Wert verglichen. Wenn der Elementtyp ein nicht benutzerdefinierter (benutzerdefinierter) Typ ist, wird die Equals Implementierung dieses Typs verwendet.
Bei dieser Methode handelt es sich um einen O()-Vorgang, wobei n es sich um einen O(n)-Vorgang handeltcount.