How to use Array.FindIndex<T> method to search and returns the index of the first occurrence of an element in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = { "PHP", "C", "C++", "C#", "Java", "JavaScript",
                           "VB.NET", "VB6", "Pascal", "Python"};


            Console.WriteLine("Array.FindIndex(s, StartWithC): {0}",
                               Array.FindIndex(s, StartWithC));
        }

        private static bool StartWithC(String s)
        {
            if ((s.Substring(0, 1).ToLower() == "c"))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}


/*
run:
 
Array.FindIndex(s, StartWithC): 1

*/

 



answered Apr 16, 2016 by avibootz
...