- 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
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
Advertisements
To Continue Learning Please Login
Login with Google