Use Array.FindLast to find the string element ends with s : Array Exist Find « Data Structure « C# / CSharp Tutorial






using System;

public class Example
{
    public static void Main()
    {
        string[] letters = { "E","B", "A", "Z", "D","X",  "Y", "Q" };

        Console.WriteLine();
        foreach(string letter in letters)
        {
            Console.WriteLine(letter);
        }

        Console.WriteLine("\nArray.FindLast(letters, EndsWithS): {0}",Array.FindLast(letters, EndsWithS));
    }
    private static bool EndsWithS(String s)
    {
        if ((s.Length > 5) && 
            (s.Substring(s.Length - 6).ToLower() == "s"))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}








11.14.Array Exist Find
11.14.1.Demonstrate Predicate delegate
11.14.2.Use Array.Exists to check if a certain element exist
11.14.3.Use Array.Find to find array elements end with s
11.14.4.Use Array.FindLast to find the string element ends with s
11.14.5.Array.FindAll
11.14.6.All three generic overloads of the Array.IndexOf method.
11.14.7.Array.LastIndexOf demo
11.14.8.Using Array.TrueForAll for testing if array elements all end with string s