Array.FindLastIndex 메서드

정의

지정된 조건자에서 정의한 조건과 일치하는 요소를 검색하고 해당 조건자 또는 일부 내에서 Array 마지막으로 발생한 항목의 인덱스(0부터 시작하는 인덱스)를 반환합니다.

오버로드

Name Description
FindLastIndex<T>(T[], Predicate<T>)

지정된 조건자에서 정의한 조건과 일치하는 요소를 검색하고 전체 Array내에서 마지막으로 발생한 항목의 인덱스(0부터 시작하는 인덱스)를 반환합니다.

FindLastIndex<T>(T[], Int32, Predicate<T>)

지정된 조건자가 정의한 조건과 일치하는 요소를 검색하고 첫 번째 요소에서 지정된 인덱스로 확장되는 요소 Array 범위 내에서 마지막으로 발생한 항목의 인덱스(0부터 시작)를 반환합니다.

FindLastIndex<T>(T[], Int32, Int32, Predicate<T>)

지정된 조건자에서 정의한 조건과 일치하는 요소를 검색하고 지정된 개수의 요소를 포함하고 지정된 인덱스에서 끝나는 요소 Array 범위 내에서 마지막으로 발생한 항목의 인덱스(0부터 시작하는 인덱스)를 반환합니다.

예제

다음 코드 예제에서는 제네릭 메서드의 세 오버로드를 FindLastIndex 모두 보여 줍니다. 8개의 공룡 이름을 포함하는 문자열 배열이 생성되며, 그 중 2개(위치 1과 5)는 "사우루스"로 끝납니다. 또한 코드 예제는 문자열 매개 변수를 허용하고 입력 문자열이 "saurus"로 끝나는지 여부를 나타내는 부울 값을 반환하는 검색 EndsWithSaurus조건자 메서드를 정의합니다.

FindLastIndex<T>(T[], Predicate<T>) 메서드 오버로드는 배열을 끝에서 뒤로 트래버스하여 각 요소를 차례로 메서드에 EndsWithSaurus 전달합니다. 메서드가 위치 5의 EndsWithSaurus 요소에 대해 반환 true 되면 검색이 중지됩니다.

메모

C#, F# 및 Visual Basic Predicate<string> 대리자(Visual Basic Predicate(Of String))를 명시적으로 만들 필요는 없습니다. 이러한 언어는 컨텍스트에서 올바른 대리자를 유추하고 자동으로 만듭니다.

FindLastIndex<T>(T[], Int32, Predicate<T>) 메서드 오버로드는 위치 4에서 시작하여 배열의 시작 부분으로 계속되는 배열을 검색하는 데 사용됩니다. 위치 1에서 요소를 찾습니다. 마지막으로, FindLastIndex<T>(T[], Int32, Int32, Predicate<T>) 메서드 오버로드는 위치 4에서 시작하여 뒤로 작업하는 세 요소의 범위(즉, 요소 4, 3 및 2)를 검색하는 데 사용됩니다. "사우루스"로 끝나는 해당 범위에 공룡 이름이 없으므로 -1 반환합니다.

using System;

public class Example
{
    public static void Main()
    {
        string[] dinosaurs = { "Compsognathus",
            "Amargasaurus",   "Oviraptor",      "Velociraptor",
            "Deinonychus",    "Dilophosaurus",  "Gallimimus",
            "Triceratops" };

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

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

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

        Console.WriteLine(
            "\nArray.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus): {0}",
            Array.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus));
    }

    // Search predicate returns true if a string ends in "saurus".
    private static bool EndsWithSaurus(String s)
    {
        if ((s.Length > 5) &&
            (s.Substring(s.Length - 6).ToLower() == "saurus"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

/* This code example produces the following output:

Compsognathus
Amargasaurus
Oviraptor
Velociraptor
Deinonychus
Dilophosaurus
Gallimimus
Triceratops

Array.FindLastIndex(dinosaurs, EndsWithSaurus): 5

Array.FindLastIndex(dinosaurs, 4, EndsWithSaurus): 1

Array.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus): -1
 */
open System

// Search predicate returns true if a string ends in "saurus".
let endsWithSaurus (s: string) =
    s.Length > 5 && s.Substring(s.Length - 6).ToLower() = "saurus"

let dinosaurs =
    [| "Compsognathus"; "Amargasaurus"
       "Oviraptor"; "Velociraptor"
       "Deinonychus"; "Dilophosaurus"
       "Gallimimus"; "Triceratops" |]

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

Array.FindLastIndex(dinosaurs, endsWithSaurus)
|> printfn "\nArray.FindLastIndex(dinosaurs, EndsWithSaurus): %i"

Array.FindLastIndex(dinosaurs, 4, endsWithSaurus)
|> printfn "\nArray.FindLastIndex(dinosaurs, 4, EndsWithSaurus): %i"

Array.FindLastIndex(dinosaurs, 4, 3, endsWithSaurus)
|> printfn "\nArray.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus): %i"


// This code example produces the following output:
//
//     Compsognathus
//     Amargasaurus
//     Oviraptor
//     Velociraptor
//     Deinonychus
//     Dilophosaurus
//     Gallimimus
//     Triceratops
//
//     Array.FindLastIndex(dinosaurs, EndsWithSaurus): 5
//
//     Array.FindLastIndex(dinosaurs, 4, EndsWithSaurus): 1
//
//     Array.FindLastIndex(dinosaurs, 4, 3, EndsWithSaurus): -1
Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs() As String = { "Compsognathus", _
            "Amargasaurus",   "Oviraptor",      "Velociraptor", _
            "Deinonychus",    "Dilophosaurus",  "Gallimimus", _
            "Triceratops" }

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

        Console.WriteLine(vbLf & _
            "Array.FindLastIndex(dinosaurs, AddressOf EndsWithSaurus): {0}", _
            Array.FindLastIndex(dinosaurs, AddressOf EndsWithSaurus))

        Console.WriteLine(vbLf & _
            "Array.FindLastIndex(dinosaurs, 4, AddressOf EndsWithSaurus): {0}", _
            Array.FindLastIndex(dinosaurs, 4, AddressOf EndsWithSaurus))

        Console.WriteLine(vbLf & _
            "Array.FindLastIndex(dinosaurs, 4, 3, AddressOf EndsWithSaurus): {0}", _
            Array.FindLastIndex(dinosaurs, 4, 3, AddressOf EndsWithSaurus))

    End Sub

    ' Search predicate returns true if a string ends in "saurus".
    Private Shared Function EndsWithSaurus(ByVal s As String) _
        As Boolean

        ' AndAlso prevents evaluation of the second Boolean
        ' expression if the string is so short that an error
        ' would occur.
        If (s.Length > 5) AndAlso _
            (s.Substring(s.Length - 6).ToLower() = "saurus") Then
            Return True
        Else
            Return False
        End If
    End Function
End Class

' This code example produces the following output:
'
'Compsognathus
'Amargasaurus
'Oviraptor
'Velociraptor
'Deinonychus
'Dilophosaurus
'Gallimimus
'Triceratops
'
'Array.FindLastIndex(dinosaurs, AddressOf EndsWithSaurus): 5
'
'Array.FindLastIndex(dinosaurs, 4, AddressOf EndsWithSaurus): 1
'
'Array.FindLastIndex(dinosaurs, 4, 3, AddressOf EndsWithSaurus): -1

FindLastIndex<T>(T[], Predicate<T>)

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정된 조건자에서 정의한 조건과 일치하는 요소를 검색하고 전체 Array내에서 마지막으로 발생한 항목의 인덱스(0부터 시작하는 인덱스)를 반환합니다.

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

형식 매개 변수

T

배열 요소의 형식입니다.

매개 변수

array
T[]

검색할 1차원 0부터 시작하는 Array 값입니다.

match
Predicate<T>

Predicate<T> 검색할 요소의 조건을 정의하는 요소입니다.

반품

(있는 경우)로 정의된 match조건과 일치하는 요소의 마지막 발생 0부터 시작하는 인덱스입니다. 그렇지 않으면 -1입니다.

예외

arraynull입니다.

-또는-

matchnull입니다.

설명

마지막 Array 요소에서 시작하여 첫 번째 요소에서 끝나는 뒤로 검색됩니다.

전달 Predicate<T> 된 개체가 대리자에서 정의된 조건과 일치하는지 반환 true 하는 메서드의 대리자입니다. 의 array 요소는 개별적으로 에 전달됩니다 Predicate<T>.

이 메서드는 O(n) 연산이며 여기서 n 는 다음과 같습니다Lengtharray.

추가 정보

적용 대상

FindLastIndex<T>(T[], Int32, Predicate<T>)

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정된 조건자가 정의한 조건과 일치하는 요소를 검색하고 첫 번째 요소에서 지정된 인덱스로 확장되는 요소 Array 범위 내에서 마지막으로 발생한 항목의 인덱스(0부터 시작)를 반환합니다.

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

형식 매개 변수

T

배열 요소의 형식입니다.

매개 변수

array
T[]

검색할 1차원 0부터 시작하는 Array 값입니다.

startIndex
Int32

뒤로 검색의 시작 인덱스(0부터 시작)입니다.

match
Predicate<T>

Predicate<T> 검색할 요소의 조건을 정의하는 요소입니다.

반품

(있는 경우)로 정의된 match조건과 일치하는 요소의 마지막 발생 0부터 시작하는 인덱스입니다. 그렇지 않으면 -1입니다.

예외

arraynull입니다.

-또는-

matchnull입니다.

startIndex 가 유효한 인덱스 범위를 벗어났습니다 array.

설명

Array 번째 요소에서 startIndex 시작하고 끝나는 뒤로 검색됩니다.

전달 Predicate<T> 된 개체가 대리자에서 정의된 조건과 일치하는지 반환 true 하는 메서드의 대리자입니다. 의 array 요소는 개별적으로 에 전달됩니다 Predicate<T>.

이 메서드는 O(n) 연산으로, n 시작 arraystartIndex부터 시작 부분까지의 요소 수입니다.

추가 정보

적용 대상

FindLastIndex<T>(T[], Int32, Int32, Predicate<T>)

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정된 조건자에서 정의한 조건과 일치하는 요소를 검색하고 지정된 개수의 요소를 포함하고 지정된 인덱스에서 끝나는 요소 Array 범위 내에서 마지막으로 발생한 항목의 인덱스(0부터 시작하는 인덱스)를 반환합니다.

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

형식 매개 변수

T

배열 요소의 형식입니다.

매개 변수

array
T[]

검색할 1차원 0부터 시작하는 Array 값입니다.

startIndex
Int32

뒤로 검색의 시작 인덱스(0부터 시작)입니다.

count
Int32

검색할 섹션의 요소 수입니다.

match
Predicate<T>

Predicate<T> 검색할 요소의 조건을 정의하는 요소입니다.

반품

(있는 경우)로 정의된 match조건과 일치하는 요소의 마지막 발생 0부터 시작하는 인덱스입니다. 그렇지 않으면 -1입니다.

예외

arraynull입니다.

-또는-

matchnull입니다.

startIndex 가 유효한 인덱스 범위를 벗어났습니다 array.

-또는-

count가 0보다 작습니다.

-또는-

startIndex 에서 count 유효한 섹션 array을 지정하지 마세요.

설명

Array 0보다 큰 경우 startIndex 1을 뺀 startIndex 값에서 시작하여 count 끝나는 count 뒤로 검색됩니다.

전달 Predicate<T> 된 개체가 대리자에서 정의된 조건과 일치하는지 반환 true 하는 메서드의 대리자입니다. 의 array 요소는 개별적으로 에 전달됩니다 Predicate<T>.

이 메서드는 O(n) 연산입니다. 여기서 ncount.

추가 정보

적용 대상