- 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
AsEnumerable() in C#
To cast a specific type to its IEnumerable equivalent, use the AsEnumerable() method. It is an extension method.
The following is our array −
int[] arr = new int[5]; arr[0] = 10; arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50;
Now, get the IEnumerable equivalent.
arr.AsEnumerable();
Example
using System; using System.Linq; class Demo { static void Main() { int[] arr = new int[5]; arr[0] = 10; arr[1] = 20; arr[2] = 30; arr[3] = 40; arr[4] = 50; var res = arr.AsEnumerable(); foreach (var ele in res) { Console.WriteLine(ele); } } }
Output
10 20 30 40 50
Advertisements