Check if every element in List matches the conditions defined by the specified predicate in CSharp

Description

The following code shows how to check if every element in List matches the conditions defined by the specified predicate.

Example


using System;//  w  w w.jav a  2  s. c om
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        List<string> myData = new List<string>();

        myData.Add("B");
        myData.Add("D");

        Console.WriteLine(myData.TrueForAll(MyCondition));

    }
    private static bool MyCondition(String s)
    {
        return s.ToLower().EndsWith("s");
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary