EN
C# / .NET - convert IEnumerable to array
0
points
In this article, we would like to show you how to convert IEnumerable to array in C#.
Quick solution:
IEnumerable<int> enumerable = new List<int> { 1, 2, 3 };
int[] array = enumerable.ToArray();
Practical example
In this example, we use ToArray()
method to convert list of integers into array.
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
IEnumerable<int> enumerable = new List<int> { 1, 2, 3 };
int[] array = enumerable.ToArray();
foreach (int i in array)
{
Console.WriteLine(i);
}
}
}
Output:
1
2
3