

- 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 return the only element that satisfies a condition
The Single() method returns the only element that satisfies a condition. If more than one such element is visible, then an error is thrown.
The following is our string array.
string[] str = { "jack", "tom", "henry", "time"};
Now, use the Single() method to get each element. Then, we have used Lambda Expression to calculate an element whose length is greater than four.
str.AsQueryable().Single(name => name.Length > 4);
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str = { "jack", "tom", "henry", "time"}; // finding string whose length is greater than 4 string res = str.AsQueryable().Single(name => name.Length > 4); Console.WriteLine(res); } }
Output
henry
- Related Questions & Answers
- Maximum size of sub-array that satisfies the given condition in C++ program
- Maximum size of sub-array that satisfies the given condition in C++
- Find permutation of first N natural numbers that satisfies the given condition in C++
- C++ code to find a point that satisfies the constraints
- How to find the number of columns of an R data frame that satisfies a condition based on row values?
- Python program to return rows that have element at a specified index
- Find the lexicographically smallest string which satisfies the given condition in Python
- How to specify that the element is read-only in HTML?
- How to delete matrix rows if a particular column value satisfies some condition in R?
- Find the only element that appears b times using C++
- How to delete a list element that only contains NA in R?
- Which normal form is the highest that satisfies the functional dependencies(DBMS)?
- How to specify that the styles only apply to this element's parent element and that element's child elements in HTML?
- Finding smallest number that satisfies some conditions in JavaScript
- 8085 program to find the element that appears once
Advertisements