Posted by: Cirilo Meggiolaro | 03/8/2009

Tip of the day #145 – Validating all items on an array

The Array class contains a function called TrueForAll that helps your application’s code to validate whether all items of an array match a Boolean expression.

Function Signature

public static bool TrueForAll<T>(T[] array, Predicate<T> match);

How to…

The following code shows an array of integers and the method TrueForAll in use checking if all items on an array are even numbers.

int[] numbers = { 2, 4, 6, 8, 10, 12, 14 };
Console.WriteLine(“Only even numbers? {0}”, Array.TrueForAll(numbers, n => n % 2 == 0));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: