C# List TrueForAll

Description

List TrueForAll determines whether every element in the List matches the conditions defined by the specified predicate.

Syntax

List.TrueForAll has the following syntax.


public bool TrueForAll(
  Predicate<T> match
)

Parameters

List.TrueForAll has the following parameters.

  • match - The Predicate delegate that defines the conditions to check against the elements.

Returns

List.TrueForAll method returns true if every element in the List matches the conditions defined by the specified predicate; otherwise, false. If the list has no elements, the return value is true.

Example


using System;//from   w ww  .  j a  v  a2  s.c o m
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 »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack