How to use Array.FindLastIndex() method to find last occurrence within a range of elements in the Array 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", "Objective-C", "Python" };


            Console.WriteLine("Array.FindLastIndex(s, EndsWithC): {0}",
                               Array.FindLastIndex(s, EndsWithC));
        }
        private static bool EndsWithC(String s)
        {
            if ((s.Substring(s.Length - 1).ToLower() == "c"))
                 return true;
            else
                return false;
        }
    }
}


/*
run:
 
Array.FindLastIndex(s, EndsWithC): 9

*/

 



answered Apr 23, 2016 by avibootz
...