
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- C# Linq TakeWhile() Method
- Differences between takewhile() and dropWhile() methods in Java 9?
- Clone() method in C#
- TrimEnd() method in C#
- Convert.ToDecimal Method in C#
- IsNullOrWhiteSpace() Method in C#
- Convert.ToSingle Method in C#
- Convert.ToChar Method in C#
- Convert.ToDateTime Method in C#
- Convert.ToInt32 Method in C#
- Convert.ToSByte Method in C#
- Convert.ToInt64 Method in C#
- Convert.ToDouble Method in C#
- ContainsKey() method in C#
- Convert.ToString Method in C#

Advertisements