
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Program to cast a type to its IEnumerable equivalent
Use the AsEnumerable() method to cast a type to its IEnumerable equivalent. It is an extension method.
For our example, we have set an array.
int[] myArr = new int[10]; myArr[0] = 1; myArr[1] = 2; myArr[2] = 3; myArr[3] = 4; myArr[4] = 5;
Now, we have used the AsEnumerable() method to cast.
myArr.AsEnumerable();
Example
using System; using System.Linq; class Demo { static void Main() { int[] myArr = new int[10]; myArr[0] = 1; myArr[1] = 2; myArr[2] = 3; myArr[3] = 4; myArr[4] = 5; myArr[5] = 6; myArr[6] = 7; myArr[7] = 8; myArr[8] = 9; myArr[9] = 10; // AsEnumerable var a = myArr.AsEnumerable(); // Displaying foreach (var item in a) { Console.WriteLine(item); } } }
Output
1 2 3 4 5 6 7 8 9 10
- Related Articles
- How to convert IEnumerable to List and List back to IEnumerable in C#?
- What is a type cast in C/C++?
- How do I cast a type to a BigInt in MySQL?
- Return the copy of a masked array cast to a specified type in Numpy
- Convert the ASCII value sentence to its equivalent string in C++
- Convert the specified string representation of a logical value to its Boolean equivalent in C#
- Regular cast vs. static_cast vs. dynamic_cast in C++ program
- JavaScript program to take in a binary number as a string and returns its numerical equivalent in base 10
- C# Cast method
- What does the interface IEnumerable do in C#?
- Difference between IEnumerator and IEnumerable Interface in C#
- C++ Program to Convert long Type Variables to int
- C++ Program to Convert int Type Variables to long
- Convert the value of the specified string to its equivalent Unicode character in C#
- Convert a sentence into its equivalent mobile numeric keypad sequence in C++

Advertisements