- 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# Single() Method
Get only a single element of a sequence using the Single() method.
Let’s say we have a string array with only one element.
string[] str = { "one" };
Now, get the element.
str.AsQueryable().Single();
Here is our code.
Example
using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { string[] str = { "one" }; string res = str.AsQueryable().Single(); Console.WriteLine(res); } }
Output
one
Advertisements