C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Next: The example code also shows the implementation of AsEnumerable in the .NET Framework. This only casts the parameter and returns it.
C# program that uses AsEnumerable method
using System;
using System.Linq;
class Program
{
static void Main()
{
// Create an array type.
int[] array = new int[2];
array[0] = 5;
array[1] = 6;
// Call AsEnumerable method.
var query = array.AsEnumerable();
foreach (var element in query)
{
Console.WriteLine(element);
}
}
}
Output
5
6
Implementation of AsEnumerable: .NET
public static IEnumerable<TSource> AsEnumerable<TSource>(
this IEnumerable<TSource> source)
{
return source;
}
And: To acquire a reference from one of those types to a simple IEnumerable type, you can invoke the AsEnumerable extension method.