![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Check if every List element matches the predicate conditions in C#
To check if every List element matches the predicate conditions, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo { private static bool demo(int i) { return ((i % 10) == 0); } public static void Main(String[] args) { List<int> list = new List<int>(); list.Add(200); list.Add(215); list.Add(310); list.Add(500); list.Add(600); Console.WriteLine("List elements..."); foreach (int i in list) { Console.WriteLine(i); } Console.WriteLine(list.TrueForAll(demo)); } }
Output
This will produce the following output −
List elements... 200 215 310 500 600 False
Example
Let us see another example −
using System; using System.Collections.Generic; public class Demo { private static bool demo(int i) { return ((i % 10) == 0); } public static void Main(String[] args) { List<int> list = new List<int>(); list.Add(100); list.Add(200); list.Add(300); list.Add(400); list.Add(500); list.Add(600); list.Add(700); list.Add(800); list.Add(900); list.Add(1000); Console.WriteLine("List elements..."); foreach (int i in list) { Console.WriteLine(i); } Console.WriteLine(list.TrueForAll(demo)); } }
Output
This will produce the following output −
List elements... 100 200 300 400 500 600 700 800 900 1000 True
Advertisements