IEnumerable C# with Example



IEnumerable C# with Example

In its most basic form, an object that implements IEnumerable represents a series of objects. The objects in 
question can be iterated using the c# foreach keyword. 
In the example below, the object sequenceOfNumbers implements IEnumerable. It represents a series of integers. 
The foreach loop iterates through each in turn. 
int AddNumbers(IEnumerable sequenceOfNumbers) { 
int returnValue = 0; 
foreach(int i in sequenceOfNumbers) { 
returnValue += i; 
} 
return returnValue; 
} 
 

0 Comment's

Comment Form

Submit Comment