c# Array.FindAllIndexOf which FindAll IndexOf

后端 未结 9 1946
佛祖请我去吃肉
佛祖请我去吃肉 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:57

    I'm aware that the question is answered already, this is just another way of doing it. note that I used ArrayList instead of int[]

    // required using directives
    using System;
    using System.Collections;
    
    String      inputString = "The lazy fox couldn't jump, poor fox!";
    ArrayList   locations   =  new ArrayList();      // array for found indexes
    string[] lineArray = inputString.Split(' ');     // inputString to array of strings separated by spaces
    
    int tempInt = 0;
    foreach (string element in lineArray)
    {
         if (element == "fox")
         {
             locations.Add(tempInt);   // tempInt will be the index of current found index and added to Arraylist for further processing 
         }
     tempInt++;
    }
    

提交回复
热议问题