c# - How can Array use LINQ extension methods since Array does not implent IEnumerable interface -



c# - How can Array use LINQ extension methods since Array does not implent IEnumerable<T> interface -

here programme :

static void main(string[] args) { int[] myarr = new int[] { 4,6,2,1}; //call where() linq method var myevennumbers = myarr.where(n => n % 2 == 0 ); console.read(); }

but when definition of where() extension method in enumerable class

public static ienumerable<tsource> where<tsource>(this ienumerable<tsource> source, func<tsource, bool> predicate); public static ienumerable<tsource> where<tsource>(this ienumerable<tsource> source, func<tsource, int, bool> predicate);

the type of source ienumerable<t>.

my question is: array class not implement ienumerable<t> how can still utilize where() extension method on array ?

an array implement ienumerable icollection (and generics) , host of other ones

foreach (var type in (new int[3]).gettype().getinterfaces()) console.writeline(type);

produces

c# linq

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -