c# Array.FindAllIndexOf which FindAll IndexOf

后端 未结 9 1968
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 08:16

I know c# has Array.FindAll and Array.IndexOf.

Is there a Array.FindAllIndexOf which returns int[]?

9条回答
  •  感情败类
    2020-11-29 08:54

    Searches for an element that matches the conditions defined by the specified predicate, and returns all the zero-based index of the occurrence within the entire System.Array.

    public static int[] FindAllIndex(this T[] array, Predicate match)
    {
        return array.Select((value, index) => match(value) ? index : -1)
                .Where(index => index != -1).ToArray();
    }
    

提交回复
热议问题