- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to check whether the elements of a sequence satisfy a condition or not
Use All() Method to check whether the elements of a sequence satisfy a condition or not. Even if one of the element do not satisfy the set condition, the All() method returns False.
To set conditions, use Lambda Expressions. Below shows a condition to check whether all the elements are greater than 20 or not.
myArr.AsQueryable().All(val => val > 20);
Let us see an example.
Example
using System; using System.Linq; class Demo { static void Main() { int[] myArr = {7, 15, 22, 30, 40}; // checking if all the array elements are greater than 20 bool res = myArr.AsQueryable().All(val => val > 20); Console.WriteLine(res); } }
Output
False
Advertisements