How to use TrueForAll to check all list elements in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
					
public class Program
{
	public static void Main()
	{
		List<int> lst = new List<int>(new int[] { 12, 87, 34, 99, 100 });

        if (lst.TrueForAll(element => element < 200)) {
            Console.WriteLine("All elements < 200");
        }
	}
}



/*
run:

All elements < 200

*/

 



answered May 6, 2020 by avibootz
...