 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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 filter array elements based on a predicate
Set an array.
int[] arr = { 40, 42, 12, 83, 75, 40, 95 }; Use the Where clause and predicate to get elements above 50.
IEnumerable<int> myQuery = arr.AsQueryable() .Where((a, index) => a >= 50);
Let us see the complete code −
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       int[] arr = { 40, 42, 12, 83, 75, 40, 95 };       Console.WriteLine("Array:");       foreach (int a in arr) {          Console.WriteLine(a);       }       // getting elements above 70       IEnumerable<int> myQuery = arr.AsQueryable() .Where((a, index) => a >= 50);       Console.WriteLine("Elements above 50...:");       foreach (int res in myQuery) {          Console.WriteLine(res);       }    } }  Output
Array: 40 42 12 83 75 40 95 Elements above 50...: 83 75 95
Advertisements
 