- 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
TakeWhile method in C# ()
With the TakeWhile() method, you can get methods by setting a condition base on Predicate.
Firstly, declare and initialize an array −
int[] arr = { 25, 40, 65, 70};
Now, use the TakeWhile() method and predicate to get all the elements that are less than 30.
var val = arr.TakeWhile(ele => ele < 30);
Let us see the same example, wherein we have displayed the values less than 30 using Predicate −
Example
using System; using System.Linq; using System.IO; public class Demo { public static void Main() { int[] arr = { 25, 40, 65, 70}; var val = arr.TakeWhile(ele => ele < 30); foreach (int res in val) { Console.WriteLine(res); } } }
Output
25
Advertisements