2
Answers

how to use IEnumerable az an interface?

Photo of elham deljooei

elham deljooei

12y
1.1k
1
Hi everyone
I'm confused about IEnumerable. i don't know which it what's mean? and when can i use it as an interface?
I've faced with IEnumerable like this:

var sorted=
from value in values
orderby value
select value;

Diplay(sorted, "sorted:");

Public Static Void Display(IEnumerable <int> result, string header)
{
cosol.writeline ("{0}", header);
Foreach (var element in result)
cosole.write("{0}", element)
}

Answers (2)

0
Photo of Vishal Gilbile
NA 13.9k 2.9m 12y
Hello Friend,
                  Following link may help you solve your problem.

http://www.dotnetperls.com/ienumerable

With Regards,
Vishal Gilbile
0
Photo of Vulpes
NA 98.3k 1.5m 12y

IEnumerable or its generic equivalent IEnumerable<T>, is just an interface which all enumerable collections (arrays, lists etc) should implement.

Although you can't create instances of these interfaces, you can have variables of these interface types which can accept references to any object which implements them.

These interfaces are particularly important because they enable you to use the 'foreach' statement to iterate through an enumerable collection and to use the LINQ extension methods on them as well.

So, in your example, 'sorted' contains a reference to an object which implements IEnumerable<int>. In other words, it's a sequence of integers.

This can therefore be passed to your Display method which takes a parameter of that type and the sequence can then be iterated through using foreach.