Valerie Meunier

Valerie Meunier

  • 1.6k
  • 533
  • 26.1k

how to search identical element in an array?

Dec 8 2021 11:35 AM

Hi

I want to het the position of the two "Ford" in the array. The first is not a problem, but how to get the next?

Thanks

   string[] cars = { "Volvo", "BMW", "Ford", "Mazda","Ford" };
        int p = Array.IndexOf(cars, "Ford");
        Console.WriteLine("Ford is at position {0} ", p + 1);
        //p = Array.IndexOf(cars, "Ford", 1);
        //Console.WriteLine("Ford is on position {0} ", p + 1);


Answers (2)