

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 find the longest string from an array of strings using Lambda Expression
The following is our string array −
string[] arr = { "Java", "HTML", "CSS", "JavaScript"};
Use the Aggregate method and set a Lambda Expression to find the string with more number of characters.
Here, the resultant string should have more number of characters than the initial seed value i.e. “jQuery” here.
Example
using System; using System.Linq; class Demo { static void Main() { string[] arr = { "Java", "HTML", "CSS", "JavaScript"}; string res = arr.AsQueryable().Aggregate("jQuery", (longest, next) => next.Length > longest.Length ? next : longest,str => str.ToLower()); Console.WriteLine("String with more number of characters: {0}", res); } }
Output
String with more number of characters: javascript
- Related Questions & Answers
- C# Program to find the smallest element from an array using Lambda Expressions
- C# Program to find the largest element from an array using Lambda Expressions
- Finding all the longest strings from an array in JavaScript
- How to initialize an array using lambda expression in Java?
- How to find the length of the longest continuous increasing subsequence from an array of numbers using C#?
- Program to find longest common prefix from list of strings in Python
- C# Program to search for a string in an array of strings
- Java Program to Iterate over ArrayList using Lambda Expression
- What is the lambda expression to convert array/List of String to array/List of Integers in java?
- C# Program to find the largest element from an array
- C# Program to find the smallest element from an array
- How to reverse a string using lambda expression in Java?
- Lambda expression in C++
- Python program to find the number occurring odd number of times using Lambda expression and reduce function
- How to find the length of the longest substring from the given string without repeating the characters using C#?
Advertisements