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:
xxxxxxxxxx
1
IEnumerable<int> enumerable = new List<int> { 1, 2, 3 };
2
3
int[] array = enumerable.ToArray();
In this example, we use ToArray()
method to convert list of integers into array.
xxxxxxxxxx
1
using System;
2
using System.Linq;
3
using System.Collections.Generic;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
IEnumerable<int> enumerable = new List<int> { 1, 2, 3 };
10
11
int[] array = enumerable.ToArray();
12
13
foreach (int i in array)
14
{
15
Console.WriteLine(i);
16
}
17
}
18
}
Output:
xxxxxxxxxx
1
1
2
2
3
3