List.FindIndex

How works FindIndex?

public class FRef : MonoBehaviour {
    string player_n;
    public List<Prop> p = new List<Prop>();
    int idx;

    void Start()
    {
        idx = p.FindIndex(IsAlive);
        Debug.Log(p[idx].name);
    }

    bool IsAlive(Prop stats)
    {
        return stats.health == 100;
    }
}

And class.cs:

using UnityEngine;
using System.Collections;
using System;

public class Classes {

}
[Serializable]
public class Prop
{
    public string name;
    public int health;
}

I understood what this code does but I was wondering about “FindIndex”. It is very strange. Please help.

FindIndex will scan a collection until the predicate (callback given as parameter) returns true.

In that case, it will return the first element of p where IsAlive returns true for it.